[SOLVED] script to send email after 7 days of remainder
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
below script created by me for below purpose,
1. If Server mentioned in server.txt is up from 7 days then email should sent to a person.
2. Server name should mention in email subject.
3. it should run every day at particular time.
Quote:
#/bin/bash
for i in `cat /tmp/script/server.txt`
do
t=`ssh -q $i "uptime" | cut -d" " -f6`
if [ $t > 7 ]
then
echo "don't forget whatever you wanted to do" > file-containing-reminder-text
#at now+7days <<END
/usr/bin/mailx -s $i_reminder rockstar05@gmail.com <file-containing-reminder-text
fi
done
after execution got below message,
Quote:
The flags you gave are used only when sending mail.
can anyone have any suggestions/remarks to run exact script on the server.
Thanks,
You just said you had it working with the '-r' flag, and have been given MANY suggestions/remarks thus far. Better question is what happens when you actually try to run the script, now that you have read the man page on the mailx command for HP/UX?
describes the possible formats, and gives the following examples
Code:
...
at 0815 Jan 24
at 8:15 Jan 24
at 9:30am tomorrow
at now + 1 day
at -f job 5 pm Friday
...
It needes spaces between words and values.
I see now, you are beyond that.
There is another error in your [ ] test:
the "greater than" operator is -gt (not > that is interpreted as a redirection to a file!)
Last edited by MadeInGermany; 01-19-2020 at 02:09 AM.
Thanks MadeInGemany for feedback, I have corrected as much as I can. Now, below is the script.
Script,
Quote:
#/bin/bash
set -xv
for i in `cat /tmp/script/server.txt`
do
# t=`ssh -q $i "uptime" | cut -d" " -f6`
if [ `ssh -q $i "uptime" | cut -d" " -f6` -gt 7 ]
then
echo "don't forget whatever you wanted to do" > file-containing-reminder-text
/usr/bin/mailx -r rockstar05@gmail.com -s "`$i`_remainder" <file-containing-reminder-text
fi
done
Output,
Quote:
+ cat /tmp/script/server.txt
+ cut -d -f6
+ ssh -q pepsi uptime
+ [ 320 -gt 7 ]
+ echo don't forget whatever you wanted to do
+ 1> file-containing-reminder-text
+ pepsi
./mail1.sh[9]: pepsi: not found.
+ /usr/bin/mailx -s _reminder -r rockstar05@gmail.com
+ 0< file-containing-reminder-text
The flags you gave are used only when sending mail.
As per above output, I unable to fetch why again "./mail1.sh[9]epsi: not found" coming. Also, lastly, "The flags you gave are used only when sending mail".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.