Sponsored Content
Top Forums Shell Programming and Scripting Script to Run Multiple Systems Checks and mail me the results after every reboot- Linux Post 302945657 by pocodot on Monday 1st of June 2015 10:25:44 AM
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?
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
HALT(8) 							       halt								   HALT(8)

NAME
halt, poweroff, reboot - Halt, power-off or reboot the machine SYNOPSIS
halt [OPTIONS...] poweroff [OPTIONS...] reboot [OPTIONS...] DESCRIPTION
halt, poweroff, reboot may be used to halt, power-off or reboot the machine. OPTIONS
The following options are understood: --help Prints a short help text and exits. --halt Halt the machine, regardless of which one of the three commands is invoked. -p, --poweroff Power-off the machine, regardless of which one of the three commands is invoked. --reboot Reboot the machine, regardless of which one of the three commands is invoked. -f, --force Force immediate halt, power-off, reboot. Do not contact the init system. -w, --wtmp-only Only write wtmp shutdown entry, do not actually halt, power-off, reboot. -d, --no-wtmp Do not write wtmp shutdown entry. --no-wall Do not send wall message before halt, power-off, reboot. EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise. NOTES
These are legacy commands available for compatibility only. SEE ALSO
systemd(1), systemctl(1), shutdown(8), wall(1) systemd 208 HALT(8)
All times are GMT -4. The time now is 06:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy