Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a RHEL 6.1 Linux server running an IBM server side application called Clearquest. My question is I'm being asked to have a script execute the following command every hour and then have it email me the results.
The command is as follows:
Code:
/opt/rational/base/cots/flexlm.11.8/i386_linux2/lmutil lmstat -c ratinoal_redirect.dat -a
Now my question is can I just plug that command in Cron and set it to run every hour or do I need to generate some kind of Bash script and then just tell Cron to run the script every hour? Either way I just need Linux to run that command above every hour and then finally, how would I format my Crontab to also email me the results of running that command?
I have a RHEL 6.1 Linux server running an IBM server side application called Clearquest. My question is I'm being asked to have a script execute the following command every hour and then have it email me the results.
The command is as follows:
Code:
/opt/rational/base/cots/flexlm.11.8/i386_linux2/lmutil lmstat -c ratinoal_redirect.dat -a
Now my question is can I just plug that command in Cron and set it to run every hour or do I need to generate some kind of Bash script and then just tell Cron to run the script every hour? Either way I just need Linux to run that command above every hour and then finally, how would I format my Crontab to also email me the results of running that command?
Crontab (by itself) doesn't do anything but run a command when you tell it to...IT won't email you, but a script that you write CAN be run through crontab.
Writing a simple bash script to execute that command, then emailing the result (using mailx, sendemail, or a similar command), is trivial. Put your command on one line, then your mail command on the next. Shove it into cron, and you're done.
Thanks. I've never written a script in Bash or anything for that matter so I was wondering how hard would it be to write this script and or how can I figure out what this would look like?
Thanks. I've never written a script in Bash or anything for that matter so I was wondering how hard would it be to write this script and or how can I figure out what this would look like?
There are THOUSANDS of shell-scripting tutorials you can find with a quick Google search. Even lots of sample scripts on here, too. Again, not hard to write, you can do it with two lines, one being the command you've already got.
I would personally put everything in the script. (Note that I think you also have a typo in the file name, carlosinfl; shouldn't it be rational_redirect.dat instead?)
Code:
#!/bin/bash
SUBJECT="License report"
RECIPIENT="you@example.com"
/opt/rational/base/cots/flexlm.11.8/i386_linux2/lmutil lmstat -c rational_redirect.dat -a 2>&1 | mail -s "$SUBJECT" "$RECIPIENT" &>/dev/null
In the simplest case, you can just save the above as a script in /etc/cron.hourly. Make sure it is runnable by root (chmod 0755 /etc/cron.hourly/filename). You can even test it immediately using sudo /etc/cron.hourly/filename if you wish.
Crontab (by itself) doesn't do anything but run a command when you tell it to...IT won't email you
Well, cron will email you. From the man page for dcron (found on Slackware at least):
Quote:
It is also common to redirect job output to a file or to /dev/null. If
you do not, and the command generates output on stdout or stderr, that
output will be mailed to the local user whose crontab the job comes from.
Of course, you need sendmail (or possibly another MTA) set up for this..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.