Bash Script - Mail Secure.log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script - Mail Secure.log
# 1  
Old 10-08-2014
Bash Script - Mail Secure.log

I'm putting together a fairly simple script, to check "secure.log" for content and email the results in a cron, nightly. The script runs fine upon manual execution, it's a problem when ran in cron. This is on a Mac server. Any thoughts?

Code:
#!bin/bash
#Email secure.log, nightly. 

Subject="Secure Log for Server"
Recipients="name@host.com"

file=/var/log/secure.log

if [ -s ${file} ] ;
 then
  mail -s "$Subject" "$Recipients"  < $file
fi


Results:

Code:
sh: /usr/local/bin/mailsecuritylogs.sh: bin/bash: bad interpreter: No such file or directory

# 2  
Old 10-08-2014
There might be ^M char

try this on vi editor

1. vi yourscript.sh

2. Press ESCKey, then type following

3.:set fileformat=unix OR :set ff=unix

4. Finally save it :x! or :wq!

OR

Use dos2unix utility
This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 10-08-2014
With cron jobs the best practice is to write everything as absolute path.

watch the missing `/' in #!/bin/bash
This User Gave Thanks to Aia For This Post:
# 4  
Old 10-08-2014
Try with #!/bin/bash instead.

You may need to give the full path to the mail command to.




Robin
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 10-08-2014
Aia and rbatte1 are right there is missing / near shebang Smilie
This User Gave Thanks to Akshay Hegde For This Post:
# 6  
Old 10-08-2014
Quote:
Originally Posted by Aia
With cron jobs the best practice is to write everything as absolute path.

watch the missing `/' in #!/bin/bash
Solved! Can't believe I missed this. Thanks, all.
This User Gave Thanks to Nvizn For This Post:
# 7  
Old 10-08-2014
You are welcome. Sometimes a new pair of eyes see something you have been looking at for ages. Glad we could all help.

Smilie



Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need in for a script that should check for errors in multiple log file (approx 2500) and should mail

hello everyone, I am new to linux and got this deliverable to write a script that should check for error in multiple log file (count is approx 2500 log files on single server) and once error is found, it should mail that error My logic says: we can put all log files path/location in one... (2 Replies)
Discussion started by: Pratik_CTS
2 Replies

2. Shell Programming and Scripting

Bash script for looking in log file

Hello, I'm a beginner in shell scripting. I would really appreciate some help from the forum. I want to write a small script that will look in apache error log. If it finds the appropriate word. It would execute some commands. In my case the apache error log is situated in:... (2 Replies)
Discussion started by: ajaysingh99
2 Replies

3. Shell Programming and Scripting

Shell script for creating log file and sending mail?

Hi , I am trying to create shell script which will help me to compare file name in two folder. There is a multiple file store in 2 folder.I want to compare that with the name. If all the file are same then send a mail that "all date is same" if not then create one log file which contain... (4 Replies)
Discussion started by: san_dy123
4 Replies

4. Solaris

how to find whether audit log is secure?

How do i find if audit logs is secured inside Solaris 10? · Verify that that audit log files are secured and owned appropriately. this is the question (1 Reply)
Discussion started by: werbotim
1 Replies

5. Cybersecurity

How can i secure my personal data and E-mail id?

Today the problem of hacking is increasing day by day so in this situation how can i secure my personal data and E-mail id? Please reply me soon. (1 Reply)
Discussion started by: andrepitt77
1 Replies

6. Shell Programming and Scripting

Generate script perl mail log not work

Dear unix forum members, I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format: authen@domain.com | sender@domain | recipient@domain exam account1@domain1.com | sender2@domain2.com |... (3 Replies)
Discussion started by: puka
3 Replies

7. Cybersecurity

/var/log/secure* mysteriously empty!

Hello everyone. I'm a newbie and this is my first post, and I'm hoping to get some help understanding what happened on my server. I did as much research as I could, but now I turn to the forums for help :) I've set up a VPS server and I "thought" I had good enough security on it, but all of a... (2 Replies)
Discussion started by: antondev
2 Replies

8. Red Hat

/var/log/messages and secure not updating

Hello all, I recently deleted some lines from the messages and secure files, in /var/log and now they are not keeping a log anymore. The last update shows the date of when I deleted the lines. I had to delete some failed login attempts to stop denyhosts from blocking the ips (probably not the... (3 Replies)
Discussion started by: z1dane
3 Replies

9. Shell Programming and Scripting

mail log parsing script in need of makeover

Dear unix forum members, I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format: sender@domain,recipient@domain The logs look something like this: 06:50:04 0048317AC863: client=localhost.com 06:50:04 0048317AC863:... (7 Replies)
Discussion started by: jjamd64
7 Replies

10. Shell Programming and Scripting

Mail using bash script

Hi, I am trying to write a script which emails the status of the job to the client. I am using bash script. I tried using mailx and the shell throws an error that 'command not found'. is mailx not supported in bash. Alternatively, is there any command that i can use for sending email in bash? ... (5 Replies)
Discussion started by: borncrazy
5 Replies
Login or Register to Ask a Question