Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. And see here for current known issues.

New Member

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

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
Cisco Employee

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

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

4 REPLIES
Cisco Employee

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

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.

New Member

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

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

Cisco Employee

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

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

New Member

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

You rock Joe!!!

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

Thanks man-

260
Views
5
Helpful
4
Replies
CreatePlease login to create content