LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-20-2011, 09:30 AM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
Question Need Help / Advice For Creating a Script


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?
 
Old 09-20-2011, 09:56 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by carlosinfl View Post
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.
 
Old 09-20-2011, 11:09 AM   #3
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
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?
 
Old 09-20-2011, 12:22 PM   #4
mmrtnt
LQ Newbie
 
Registered: Nov 2006
Location: las vegas, nevada
Distribution: fedora core x
Posts: 25

Rep: Reputation: 8
A mailer script:

Code:
#!/bin/sh

# mailer.sh
# USAGE: mailer.sh somefilename.txt

SUBJECT="Test Mail"
MAILBODY=`cat $1`
MAILTO="recipient@domain.com"
mail -s "$SUBJECT" "$MAILTO" <<-EOF
$MAILBODY
EOF
And the modified cron:

Code:
/opt/rational/base/cots/flexlm.11.8/i386_linux2/lmutil lmstat -c ratinoal_redirect.dat -a; mailer.sh somefilename.txt
 
1 members found this post helpful.
Old 09-20-2011, 01:01 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by carlosinfl View Post
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.
 
Old 09-20-2011, 01:13 PM   #6
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
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.
 
1 members found this post helpful.
Old 10-03-2011, 01:30 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need advice on a script HyperTrey Programming 5 04-01-2008 01:44 PM
Need advice on creating an alias thorney Linux - General 2 11-27-2005 07:33 PM
Creating a network with FC3 and FC4, Need advice A6Quattro Linux - Networking 1 07-21-2005 08:21 AM
Advice on creating new directory satimis Linux From Scratch 4 06-27-2005 08:34 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration