01-24-2008 04:06 PM
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
Solved! Go to Solution.
01-24-2008 06:52 PM
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
01-24-2008 04:32 PM
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.
01-24-2008 04:55 PM
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....
01-24-2008 06:52 PM
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
01-25-2008 03:59 AM
You rock Joe!!!
I'll give it a try in awhile....
Thanks man-
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide