LMS 2.2 Netconfig from cmd line and mailing output .txt file ?

Answered Question
Jan 24th, 2008

The notes below I took on how to run netconfig jobs from the command line. What I would like to be able to do is email the output.txt file to my email address. Any ideas on how I could do this?

•Create a file that has all the devices the file is to be executed on. Example, /opt/CSCOpx/bin/devices.

•Create a file with the commands to be executed. Example, /opt/CSCOpx/bin/commands.

•chmod 666 /opt/CSCOpx/bin/devices.

•chmod 666 /opt/CSCOpx/bin/commands.

•from /opt/CSCOpx/bin run the command - ./cwconfig netconfig -u adminId -p adminPwd -createjob -mode enable -failure CONTINUE -devicefile /opt/CSCOpx/bin/devices -commandfile /opt/CSCOpx/bin/command

I have this problem too.
0 votes
Correct Answer by Joe Clarke about 8 years 10 months ago

Parse the output of the cwconfig command. For example:

jobid=`cwconfig ... | grep jobId | cut -d'=' -f2`

Then, loop waiting for the job to complete. When it does, email the file:

cat /path/to/results.txt | sendmail [email protected]

Something like this should work:

jobid=`cwconfig ... | grep jobId | cut -d'=' -f2`

running=1

while [ ${running} -eq 1 ]; do

status=`cwconfig netconfig -listjobs -u admin -p admin -status R | grep "JobId: ${jobid}"`

if [ -z "${status}" ]; then

results=`ls -1 /var/adm/CSCOpx/files/jobs/config/${jobid}/results.*.txt 2> /dev/null`

if [ -n "${results}" ]; then

cat ${results} | sendmail [email protected]

fi

running=0

fi

done

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
Joe Clarke Thu, 01/24/2008 - 16:32
getwithrob Thu, 01/24/2008 - 16:55

When I run a Netconfig job, the output is written to /var/adm/CSCOpx/files/jobs/config/jobid#. The only file of interest to me is the .txt file that gets put written to this same directory.

There are a ton of other files in that directory if a ton of devices are selected. I'd rather not email these files....

Correct Answer
Joe Clarke Thu, 01/24/2008 - 18:52

Parse the output of the cwconfig command. For example:

jobid=`cwconfig ... | grep jobId | cut -d'=' -f2`

Then, loop waiting for the job to complete. When it does, email the file:

cat /path/to/results.txt | sendmail [email protected]

Something like this should work:

jobid=`cwconfig ... | grep jobId | cut -d'=' -f2`

running=1

while [ ${running} -eq 1 ]; do

status=`cwconfig netconfig -listjobs -u admin -p admin -status R | grep "JobId: ${jobid}"`

if [ -z "${status}" ]; then

results=`ls -1 /var/adm/CSCOpx/files/jobs/config/${jobid}/results.*.txt 2> /dev/null`

if [ -n "${results}" ]; then

cat ${results} | sendmail [email protected]

fi

running=0

fi

done

Actions

This Discussion