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:

@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:

@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?

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.

@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

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.

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

Failed.

-pocodot

Try /path/to/mail.