Shell / script pointers needed

Shaitan

Registered
Hi all, my 1st post here after some lurking (and searching :))

I am a complete *nix/shell newbie, and migrated to OSX just last week, but I've managed to establish a few backup routines through sophisticated cut&paste :D. The only thing missing now are a couple of "scripts" that'll let me know when things are about to go kaboom :)

So basically, what I'm trying to do (but can't even figure out where to begin) is
- Test if a specific volume ("Mirror") is mounted, and if not send me an e-mail telling me (or somebody else in my team) to sort it asap
- Test the result of "/usr/sbin/fcsctl status", and if the returned string contains "not" send an e-mail again urging to restart fsctl (or maybe even restart it from shell?)

I really have no idea where to begin, tho I suspect I'll have to use grep somehow, but that's about as far as I am atm.

Any help appreciated, thx :)
 
Ok, there's a few little tricks you'll want to work out.
+ Sending email from a script: probably the easiest way for you to do this is to create an AppleScript to send the email message, and use the "osascript" shell command to run that AppleScript.
+ Test if a volume is mounted: In bash shell scripting this would be the ifexist command. You could also try using "grep" on an "ls" to see if the volume folder is there.
 
Could I do something like (pseudo code)

Ifexist /volumes/volumename
fi
else mail -s "Mount volumename" me@my.domain
fi

And if so, how do I properly format it?
 
And for the other one (status test)

/usr/sbin/fcsctl status > status.txt
grep not status.txt
if grep = not
mail -s "FCSCTL DOWN!!" me@my.domain
fi
else
fi

Putting the result in a variable and do grep on that (if possible) is probably even better so I don't have to make a new (overwrite) the file for each test...
 
gumse said:
#!/bin/bash
if [ -f daisy.wav ]
then
echo "testfile exists! "
fi

Thanks a lot, that pretty much solved it :)
The "if" man page isn't terribly helpful, but I guess I've got it now

#!/bin/bash
today=`date +%A`
if ! [ -e /library/firstclass\ server/backup/$today/mirror/.trashes ]
then
mail -s "$today is not mounted!" me@my.domain < /library/firstclass\ server/sh/annoy.txt
fi


Now to figure out how to translate $today to norwegian ($idag) to match the disk labels for the mail subject :confused:
 
Hey there,

Commands you might want to have a look at:
mail
crontab

Also:
#!/bin/bash
if [ ! -z "$(/usr/sbin/fcsctl status | grep not)" ]; then
echo "Not there ..."
#you could put in code to restart fcsctl here
fi

Cheers,
C
 
Back
Top