LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-10-2020, 11:17 AM   #16
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211

Yup. Again: Read the man page for at on your system. Figure out what the errors mean.
I'm out.
 
1 members found this post helpful.
Old 01-16-2020, 08:20 AM   #17
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
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.
Suggestion/modification welcomes.

Awaiting for reply,

Thanks
 
Old 01-17-2020, 01:32 AM   #18
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
now correct with -r option in mailx command ...

can anyone have any suggestions/remarks to run exact script on the server.

Thanks,
 
Old 01-17-2020, 06:53 AM   #19
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rockstar05 View Post
now correct with -r option in mailx command ...

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?
 
Old 01-18-2020, 06:57 PM   #20
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
it works fine ...!!!

But I wanted to make much better script which will not fail in any condition.

Now, 2nd time it failed,

Quote:
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` > 7 ]
then
echo "don't forget whatever you wanted to do" > file-containing-reminder-text
/usr/bin/mailx -s `$i`_reminder -r rockstar05@gmail.com <file-containing-reminder-text
fi
done
+ cat /tmp/script/server.txt
+ cut -d -f6
+ ssh -q PEPSI uptime
+ [ 319 ]
+ 1> 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.
The only difference I put first time I put 2 servers in /tmp/script/server.txt, and 2nd time I put 1 server.

is there anything wrong ?

Regards,
 
Old 01-19-2020, 01:57 AM   #21
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The HP-UX man page
Code:
man at
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.
 
Old 01-19-2020, 02:09 AM   #22
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
[double post deleted]

Last edited by MadeInGermany; 01-19-2020 at 02:12 AM.
 
Old 01-19-2020, 09:52 AM   #23
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
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".

not sure, where I loss my eye in the script.

Thanks,
 
Old 01-19-2020, 12:20 PM   #24
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Don’t use backticks around the variable...makes it be interpreted as a command, which is then “not found”

Fix one error at a time. The debug output is showing you that the mailx command got broken up.
 
Old 01-20-2020, 09:44 AM   #25
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
Yeah corrected. replacing -r with -m.
 
Old 01-21-2020, 02:19 AM   #26
rockstar05
Member
 
Registered: Dec 2011
Posts: 83

Original Poster
Rep: Reputation: Disabled
anything else ? I also wanted to add multiple email-ids who is in copy.

how can I add here in the same for loop ?
 
Old 01-27-2020, 01:12 AM   #27
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
I think that mailx takes multiple mail addresses:
Code:
mailx -s subject a@b.com c@d.net
See its man page
Code:
man mailx

Last edited by MadeInGermany; 01-27-2020 at 01:16 AM.
 
  


Reply

Tags
email, script, shell, unix



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Canonical cuts the price of the Ubuntu Edge to $695 for the remainder of its Indiegog jeremy Linux - News 0 08-08-2013 11:09 AM
Perl email::send.. how to send the email? hawk__0 Programming 6 12-24-2009 01:53 PM
RH 3u8ES rpm problem installing remainder of release batzion Linux - General 2 12-06-2009 11:26 PM
Script to send mail to admin after server idle for 5 days siddhartha_ece2004 Programming 12 07-22-2008 05:13 AM
How to display remainder in Bash script packets Linux - Newbie 6 12-01-2007 01:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration