Sponsored Content
Top Forums Shell Programming and Scripting Simple script to test mountGpoint for read-write Post 302992015 by jaapar on Monday 20th of February 2017 03:20:05 PM
Old 02-20-2017
Quote:
Originally Posted by drysdalk
Hi,

A script like this set up on ServerA should do the trick.

Code:
#!/bin/bash
date=`/bin/date +%Y%m%d%H%M%S`

email_to="unixforum@localhost"
email_subject="Something went wrong"
email_body="Uh-oh"

server="localhost"

if ! /usr/bin/ssh "$server" "/usr/bin/touch /mnt/testfile.$date" >/dev/null 2>/dev/null
then
        echo "$email_body" | /usr/bin/mail -s "$email_subject" "$email_to"
        exit 1
fi

exit 0

The 'date' variable at the top just creates a string via the 'date' command that consists of the year, month, date, hour, minute and second all run together. I went with this since you didn't specify any particular format, but this should do for most purposes (if the script only runs at most once per second, anyway).

The next three variables define the recipient, subject and body of the e-mail message. You can customise those all you like.

Finally, the variable 'server' defines the remote server that the 'ssh' command will use to connect to. You'll want to change this to the details of whatever ServerB is.

The basic idea of the script is that it connects to the remote server, and if the 'touch' command (or the 'ssh' command itself) returns a non-successful exit value for any reaason, it then proceeds to send the e-mail.

Here's an example session of it running, in a situation where the touch command at the remote end (which is really just 'localhost' in my test case) fails.

Code:
$ whoami
unixforum
$ ./script.sh 
$ mail
"/var/mail/unixforum": 1 message 1 new
>N   1 unixforum@localhost Mon Feb 20 15:17  15/654   Something went wrong
? 1
<e-mail headers appear here, redacted>

Uh-oh
? d 1
? q
Held 0 messages in /var/mail/unixforum
$

Hope this helps.
Yes thank you!!! script worked like a charm!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script with read/write Files

Hello, I am a Newbie in ksh Unix Script. So I must write a ksh/sh script who read character at a position in a File. So also it must read all the lines who belongs at these characters , then write these lines in a another File. Can you help me , or give little councils to advance with my... (5 Replies)
Discussion started by: steiner
5 Replies

2. UNIX for Dummies Questions & Answers

help with simple read script!

Hi y'all...I've been wracking my brain over this very simple script that reads in a textfile and echos each line. But I keep getting an error. Below is my script: #!/bin/bash while read myline do echo $myline done < t_file-20080221.01.asc The error I am getting is: syntax error... (1 Reply)
Discussion started by: kevlar28
1 Replies

3. Shell Programming and Scripting

i want to write a script to test the folder permissions

Hi All, I want a script to test folder permissions.( to alert me if a folder /abc/xyz does not have 775 permissions). i want to test /abc/xyz is having 775 permissions or not if not it has to alert me. Please help me ASAP Thanks in advance (4 Replies)
Discussion started by: rajesh212512
4 Replies

4. Shell Programming and Scripting

Bash Script to Read & Write on different directories

Hi, root@server] df -h 121G 14G 101G 12% /home 147G 126G 14G 91% /backup We having our site files and images are storing in /backup/home/user/files/ through symbolic link created in /home directory pointing in /backup directory as following. root@server] cd /home... (1 Reply)
Discussion started by: mirfan
1 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

7. Shell Programming and Scripting

Write shelll script to read file location

hi all i have a problem how to read file location..I read file as FILE=/home/tmp/new.file.but t is not useful for me.But i want my script read file location where the file is and copy in directory at boot time. Every time of booting files are copied in respective folder.please help !!!!:) (2 Replies)
Discussion started by: shubhig15
2 Replies

8. UNIX for Dummies Questions & Answers

Simple script to write new lines in a text file

Hello, I have a comma seperated data sheet with multiple fields of biological data. One column contains the ID name of the sample, where there could be more than one sample separated by a comma. I would like a script that reads this field, and for each sample ID, copies the entire line and writes... (18 Replies)
Discussion started by: torchij
18 Replies

9. Shell Programming and Scripting

Need a perl script to read and write the data

Hi, I have on Designdocument in that information is stored with in tabular format.I need Perlscript to read and write the datausing perl script? Regards, Ravi (0 Replies)
Discussion started by: toravi.pentaho
0 Replies

10. Shell Programming and Scripting

Need a UNIX/perl script to read and write the data

Hi, I have on Designdocument in that information is stored with in tabular format.I need Perl/unix script to read and write the data using perl script? Regards, Ravi (4 Replies)
Discussion started by: toravi.pentaho
4 Replies
POLLRCVD(8C)															      POLLRCVD(8C)

NAME
pollrcvd - HylaFAX script for delivering facsimile received by polling SYNOPSIS
/var/spool/fax/bin/pollrcvd mailaddr faxfile devid commid error-msg DESCRIPTION
bin/pollrcvd is the command script invoked by the HylaFAX server whenever a facsimile is received as a result of a polling operation. The default script uses electronic mail to deliver the facsimile to the user that submitted the poll request, and can be controlled by editing the etc/PollDispatch shell script in the spooling area that is sourced by pollrcvd when it runs. The arguments are: mailaddr the electronic mail address of the user that submitted the poll request. faxfile the pathname of the received TIFF file relative to the root of the spooling hierarchy. commid The communication identifier associated with the call (used to include a transcript when an error occurs). devid the modem device on which the document was received. error-msg an error message that is non-null if an error was encountered during the receive operation. NOTES
The default script delivers facsimile as PostScript wrapped in MIME. FILES
/var/spool/fax spooling area /usr/sbin/faxinfo for printing information about the facsimile /usr/bin/fax2ps for converting TIFF to PostScript /usr/sbin/sendmail for delivering mail SEE ALSO
faxq(8C), hylafax-server(5F), recvq(5F) May 12, 1996 POLLRCVD(8C)
All times are GMT -4. The time now is 07:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy