cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1461
Views
5
Helpful
4
Replies

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

getwithrob
Level 3
Level 3

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

1 Accepted Solution

Accepted Solutions

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 user@company.com

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 user@company.comf

fi

running=0

fi

done

View solution in original post

4 Replies 4

Joe Clarke
Cisco Employee
Cisco Employee

I assume you mean the stdout/stderr from this command? Then something like this should work:

./cwconfig netconfig -u adminId -p adminPwd -createjob -mode enable -failure CONTINUE -devicefile /opt/CSCOpx/bin/devices -commandfile /opt/CSCOpx/bin/command 2>&1 | /usr/sbin/sendmail user@company.com

This could the last line of your sh script.

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....

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 user@company.com

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 user@company.comf

fi

running=0

fi

done

You rock Joe!!!

I'll give it a try in awhile....

Thanks man-

Review Cisco Networking for a $25 gift card