Solved

BASH Script

Posted on 2004-09-10
11
906 Views
Last Modified: 2013-12-17
Hello:

I know nothing about bash scripting and need help compiling a script that would automate the  following. (Red-Hat 9)

1. execute a script that we already have in place have in place that analyzes our maillog
2. after the script executes - output to a file...lets say maillog_analysis
3. email that file to admin.
4. I would set this up as a cron job to run at periodic intervals.

Is this possible without too much difficulty.
0
Comment
Question by:jstansley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
11 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 125 total points
ID: 12032262
If I understand your question correctly you'd need a script along the lines of:

#!/bin/sh
#
# Be nice and set a Subject and From in the mail we'll send to admin
#
host=`hostname`
cat >/tmp/maillog_analysis <<EOF
Subject: Mail Log Analysis
From: root@$host

EOF
#
# Execute the maillog analyser script and append the output to /tmp/maillog_analysis
#
/path-to/analyzer >>/tmp/maillog_analysis
#
# Mail the result to the admin account
#
/usr/sbin/sendmail -f root admin </tmp/maillog_analysis
exit

Save that to file (say /usr/local/sbin/do-maillog), edit it to set /path-to/analyzer to the path and name of your script, make it executable (chmod 755 /usr/sbin/do-maillog), and then add a crontab entry via 'crontab -e' as root like:

0 1 * * * /usr/local/sbin/do-maillog
0
 

Author Comment

by:jstansley
ID: 12034142
Thanks....I'll give this a try and see ifit flies.  Appreciate the help
0
 

Author Comment

by:jstansley
ID: 12034190
When I execute the file with ./maillogstats.............I get this
: bad interpreter: No such file or directory

Doing something wrong obviously...can you point it out?

Thanks
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:jstansley
ID: 12034593
This may help diagnose the problem.

If I just run bash <filename> it works
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12039135
": bad interpreter: No such file or directory" sounds like the magic line at the beginning of the script isn't exactly "#!/bin/sh". That line must have no leading or trailing whitespace and must end on only a Unix newline character. If you saved/wrote the script on a windows box and copied it to the server there'll b a carriage return on the line and it won't work.
0
 

Author Comment

by:jstansley
ID: 12039446
That did it...odd thing now is that the script runs fine from command line but not when set to run as a CRON. Very frustrating.  Here' what the CRON looks like

Thanks for your help

Last login: Sun Sep 12 08:33:51 2004 from host-24-225-238-137.patmedia.net
[root@SMM02 root]# crontab -e


30,59 * * * 1-7 /root/maillogstats
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12040565
If a root job fails it will mail the error report to the owner of the crontab (root in this case). Have you checked root's mail to see what the error is?
0
 

Author Comment

by:jstansley
ID: 12042827
You have been a tremendous help with this. Thanks. I found that it cannot find open sendmail to mail the results. It is just odd that I can run it manually and not via CRON. I am just getting my feet wet so to speak with LINUX and it's like learning a new language. Thanks again. Now let me see if I can get the script to run via CRON.
0

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question