Script to Run Multiple Systems Checks and mail me the results after every reboot- Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Run Multiple Systems Checks and mail me the results after every reboot- Linux
# 1  
Old 06-01-2015
Script to Run Multiple Systems Checks and mail me the results after every reboot- Linux

Hello,

I'm trying to create a mechanism wherein a set of Production servers will email me the results of system checks like Uptime, NFS Mounts and a Process after every scheduled reboot.

For this, I figured I'd use the @reboot parameter that crond comes with.
I have added the below onliner in crontab for root:
Code:
@reboot up=`/usr/bin/uptime| cut -d, -f1,2`; tck=`ls -l /path/to/mounted/file`; pst=`ps -ef | grep ManageProcess`; echo -e "Uptime: $up \n\nMount Check: $tck \n\nManageProcess  Check:\n\n$pst"| mail -s "[DIFMON]`hostname` is UP After Reboot"  pocodot@mydomain.com

No mail. If I run the above line on a shell, I get proper email with all the status.

I figured the ; after each command may be cutting the command run on crontab and tried as below:

Code:
@reboot up=`/usr/bin/uptime| cut -d, -f1,2`;
@reboot tck=`ls -l /path/to/mounted/file`;
@reboot pst=`ps -ef | grep ManageProcess`;
@reboot echo -e "Uptime: $up \n\nMount Check: $tck \n\nManageProcess Check:\n\n$pst"| mail -s "[DIFMON]`hostname` is UP After Reboot" pocodot@mydomain.com

I guess crontab is possibly not able to handle variable declaration.

I dont want to run a script from crontab since this is a production server and I wont be allowed to place my script anywhere in filesystem.

Could anyone help me with this please?

Bonus question: I notice that @reboot option runs even if the crond service is restarted whereas the documents say this will run only on boot/reboot. Is this not weird?
# 2  
Old 06-01-2015
cron is not psychic. How would it know when the computer starts? It knows when it starts.

cron is not one giant shell script. Those lines are independent.

Never use echo -e. Use printf.

Code:
@reboot printf "Uptime: %s\n\nMount Check: %s\n\nManageProcess Check:\n\n%s\n" "`/usr/bin/uptime| cut -d, -f1,2`" "`ls -l /path/to/mounted/file`" "`ps -ef | grep ManageProcess`"| mail -s "[DIFMON]`hostname` is UP After Reboot" pocodot@mydomain.com

# 3  
Old 06-02-2015
Corona688

I'll keep printf in mind.

The code runs perfectly on the shell but append it to @reboot in cron and it fails. I suscpected that command piping may not be working in crontab.

Code:
@reboot echo "Hello" | mail -s "Test Mail" pocodot@mydomain.com

Failed.

-pocodot
# 4  
Old 06-02-2015
Try /path/to/mail.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a script before and after reboot automatically and send output to two locations.

Hello Team . I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are 1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ? 2. The same... (2 Replies)
Discussion started by: Varja
2 Replies

2. Shell Programming and Scripting

Need Multiple checks inside if condition in a bash shell script

Hi, I need to perform the untar and rm operation if the file found is a .tar and does not have test.tar or hello.tar as the file names. Below is the loop to check the same. for tf in *.tar do if ] then found=1 ... (1 Reply)
Discussion started by: mohtashims
1 Replies

3. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

4. Shell Programming and Scripting

Script to Execute command and mail results

HI everyone, I would like to have a script to run a certain linux command and mail the results or output of this command. This shell is to be later on set as cronjob. thanks in advance. (9 Replies)
Discussion started by: patrickminas
9 Replies

5. Shell Programming and Scripting

How to run script automatically on reboot as root user?

Hi friends,,, I am running one server on Ubuntu 12.04 LTS 32-bit, some times my pc restarts automatically, with no reason, I have a script to start server which requires root password. in this directory /myserver/start_server.sh How can I do this ? and some scripts I am having that I... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

6. Shell Programming and Scripting

How to run multiple instances of shell script in linux?

How we can run the multiple instances of the script? I need to run the script which I am calling from the below function.I can doit with cron but I don't want to put it in the cron.This cript dploy the build and here I want when the build stage then it should run with multilpe instances of... (6 Replies)
Discussion started by: anuragpgtgerman
6 Replies

7. Shell Programming and Scripting

script to reboot multiple hosts

Hi Expert, How to create a script to reboot multiple hosts in linux? Thank you. (5 Replies)
Discussion started by: regmaster
5 Replies

8. Shell Programming and Scripting

Need a script to run on multiple mail servers..

Hello, I am a Unix newbie and I need a script in which I can run a command on multiple servers at work. The command is to start a storage process and I am sick of doing it manually on all servers.. Here's the command: /opt/bss/bin/snmptable -CB -v2c -c P67LzuBm hostname hrStorageTable... (4 Replies)
Discussion started by: kinyyy
4 Replies

9. Linux

Run a script during reboot/startup

Hi all, i have a script in /etc/init.d directory. -rwxr-xr-x 1 root root 26 Mar 28 16:00 myscript I need it to run when my linux reboots/startup. However is it not being executed. Do i need to put in in the rc.local directory? (1 Reply)
Discussion started by: new2ss
1 Replies

10. Shell Programming and Scripting

Run expect script in systems that don't support it out of box

Noob question .. My Java based application needs to change some user passwords based on some user actions. Since this application can run on Redhat AS2.1 / AS4.0 / Solaris 9 etc, the most safe and portable solution that I could think of was: Use expect. Now, expect is not available on all... (1 Reply)
Discussion started by: namityadav
1 Replies
Login or Register to Ask a Question