 |
 |
- Script to test if a server is mounted, to use with CRON (help)
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2001
Location: not far from my GSM phone
Status:
Offline
|
|
I have some knowledge in UNIX, but I miss all the necessary info about programming/scripting.
I have a command thet mounts an afp server, it works.
I need the code that would check if that server is mounted, and execute the [mount_afp ...] command only if the server is not mounted.
Can anyone give me the necessary into and/or code?
Thank you in advance for your help.
|
|
Lao_Tseu
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Do you need to do this via the Terminal or could you use an Applescript?
Craig
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2001
Location: not far from my GSM phone
Status:
Offline
|
|
Originally posted by suthercd:
Do you need to do this via the Terminal or could you use an Applescript?
Craig
In the setup I have, CRON tasks launch a backup of folders from the server to a local HD. I believe that it works even if nobody is logged in.
I might be wrong, but it seems it worked.
The check/mount script should run in the same conditions, would an AppleScript work?
|
|
Lao_Tseu
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Sure. You can call an Applescript from the command line with the osascript command. That can be incorporated in your Cron scripts and schedules.
There is a man page for osascript, the basic syntax is osascript -e 'applescript commands'
You could try to make an alias for the volume you are wanting to verify and use error trapping to tell if the volume is mounted or not. Kowing that, either mount the volume or just execute the cron task.
HTH
Craig
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
It's pretty easy. Just make a script that looks for the mount point.
Code:
if [ ! -f /Volumes/somedrive ]; then
[mount_afp command]
fi
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2001
Location: not far from my GSM phone
Status:
Offline
|
|
Originally posted by Arkham_c:
It's pretty easy. Just make a script that looks for the mount point.
Code:
if [ ! -f /Volumes/somedrive ]; then
[mount_afp command]
fi
Thanx a lot Arkham_c!
|
|
Lao_Tseu
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2001
Location: not far from my GSM phone
Status:
Offline
|
|
I adapted the script to my environment. I have been trying hard to use it, but even after searching for crontab info and ssh script info, I cannot make it work.
So please can someone help me:
1. where do I have to save the file conmtaining my command
2. is the #!/bin/csh header in the first line correct
3. I created a folder ~/bin and saved the script as a text file called <mymount> without extension
4. I created a crontab entry: ~/bin/mymount. When I un that command from terminal I get: if: Expression Syntax
I am sure that I'm not far from the solution, but please tell me what the missing piece is...
Thanks
|
|
Lao_Tseu
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by lapinos:
I adapted the script to my environment. I have been trying hard to use it, but even after searching for crontab info and ssh script info, I cannot make it work.
So please can someone help me:
1. where do I have to save the file conmtaining my command
2. is the #!/bin/csh header in the first line correct
3. I created a folder ~/bin and saved the script as a text file called <mymount> without extension
4. I created a crontab entry: ~/bin/mymount. When I un that command from terminal I get: if: Expression Syntax
I am sure that I'm not far from the solution, but please tell me what the missing piece is...
Thanks
I think a csh or tcsh shell script "if" block is closed with "endif" not "fi". "fi" is used in bash and sh shell scripts.
Of course... the script might "just work" if you change #!/bin/csh to #!/bin/sh ;-)
I use a similar scheme for mirroring all of /home on my Linux server to a separate disk. On the backup disk there is a "marker" file called .MirrorOK
I also have the same marker file in /home/ .... like this:
Code:
echo Doing sanity checks...
logger Doing sanity checks...
mount /dev/hde1 /back
if [ -f /home/.MirrorOK -a -f /back/home/.MirrorOK ];
then {
echo Sanity checks PASSED, starting mirror
logger Sanity checks PASSED, starting mirror
[backup command]
echo Mirror COMPLETE
logger Mirror COMPLETE
umount /back
echo Mirror volume \(/back\) Unmounted.
logger Mirror volume \(/back\) Unmounted.
}
else {
umount /back
echo Sanity checks FAILED for /home, PANIC: .MirrorOK file not found
logger Sanity checks FAILED for /home, PANIC: .MirrorOK file not found
}
fi
From the first if statement you can see that BOTH .MirrorOK files on both volumes have to exist in order for the backup to proceed. If it fails the test then the script logs and echoes a "PANIC" message and exits. If the statement returns true then the backup proceeds. The backup volume is ONLY mounted for the purpose of backups otherwise it is unmounted.
The above is "sh" script BTW and is headed by #!/bin/sh I have been using it for 6 years on all my Linux servers and it has never failed. The script is located in /etc/cron.daily/ Linux runs all scripts in that folder at 4:02 in the morning each day.
Mac OS X has similar functionality. Take a look in /etc/ for a file called daily
daily is a general maintenance and cleanup script that gets run once a day (at about 3:15 in the morning). It will also source a file called /etc/daily.local if such a file exists. That is where I would put my backup script. Also read the rest of that /etc/daily file... some good examples of how to do shell scripting. There is also an /etc/weekly and /etc/monthly you might want to look at.
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
|
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2001
Location: not far from my GSM phone
Status:
Offline
|
|
thank you for your input.
Am I obliged to leave the script in the /etc/ hierarchy?
I would like to call it as I saw it in a cron tutorial: ~/foldername/scriptname
When I run the connexion script alone it works, but when I try to run the shell script I get dirrefent errors, the latest one being:
/Users/theuser/bin/mountscript: [/usr/bin/osascript: No such file or directory
I am lost...
thanx
|
|
Lao_Tseu
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Oh I agree!!!
Will be nice when tcsh is NOT the default on Mac OS X. Is there any commentary on why Apple chose tcsh as the default shell?
|
|
-DU-...etc...
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Oct 2001
Location: Philly
Status:
Offline
|
|
Originally posted by lapinos:
thank you for your input.
Am I obliged to leave the script in the /etc/ hierarchy?
I would like to call it as I saw it in a cron tutorial: ~/foldername/scriptname
You are under no obligation to put it in any particular place, but for convenience's sake, tidyness, and being able to find all of your admin scripts later, it's a good idea to pick on spot and stick with it. /usr/local is a popular choice - many admins set up a whole heirarchy in /usr/local of etc, bin, sbin, and so forth. That makes it easier to distinguish between homegrown stuff and factory stuff, and it makes backing up your changes or carrying them over to a new machine easier.
When I run the connexion script alone it works, but when I try to run the shell script I get dirrefent errors, the latest one being:
/Users/theuser/bin/mountscript: [/usr/bin/osascript: No such file or directory
That sounds like a path issue, but not having OS X in front of me... Double check the paths for all of your commands in the script and make sure you are using the fully qualified command?
mathias
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status:
Offline
|
|
Originally posted by lapinos:
/Users/theuser/bin/mountscript: [/usr/bin/osascript: No such file or directory
It looks to me like an "open square bracket" test command is being included in the path because there is no space after it. Putting in the space should fix that problem.
Originally posted by utidjian:
Will be nice when tcsh is NOT the default on Mac OS X. Is there any commentary on why Apple chose tcsh as the default shell?
I can't speak for Apple but I think that tcsh is one of the two most feature-rich shells for interactive use. Bash was originally written for scripting and in my opinion, still lags behind tcsh and zsh in terms of interactive features. (I can't speak about ksh) The completion mechanisms of tcsh and zsh leave that of bash in the dust. I wouldn't want to script in tcsh but for users that don't often use tests and loops in the command line, I think that tcsh is a good choice. I use zsh myself but I can tell you from experience that it's a bear to configure. While I think its worth the effort, I can see why it would be a poor choice for most Mac users.
|
|
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status:
Offline
|
|
Originally posted by Gary Kerbaugh:
I can't speak for Apple but I think that tcsh is one of the two most feature-rich shells for interactive use. Bash was originally written for scripting and in my opinion, still lags behind tcsh and zsh in terms of interactive features. (I can't speak about ksh) The completion mechanisms of tcsh and zsh leave that of bash in the dust. I wouldn't want to script in tcsh but for users that don't often use tests and loops in the command line, I think that tcsh is a good choice. I use zsh myself but I can tell you from experience that it's a bear to configure. While I think its worth the effort, I can see why it would be a poor choice for most Mac users.
I have often heard this said (completion features) and perhaps I mis-understand what people mean by that. I am willing to change my opinion if it were at all possible for me to realize these wonderful completion features... however...
When I do something like
cd Li
and then hit [Tab] it completes in tcsh just as it would in bash to:
cd Library/
however I can keep hitting [Tab] and nothing happens in tcsh... while in bash it gives me the possible completions. In bash not only does it give me possible completions but if there are a bazillion of them it pages them nicely. I find this little completion feature of bash to be FAR superior to the one in tcsh. Perhaps it is configureable in tcsh or I am missing something... but the default behavior in bash is already there. I don't have to type ^D (Ctrl-D) or whatever in bash... just the [Tab] key. Ctrl-D is a really bad choice BTW since it can also log you out... not critical but irritating.
OK after reading the manpages for both I can see that autocompletion is configureable in tcsh. To bad it isn't set that way by default. If you look at the manpage for bash you will see a far richer set of completion features than the current tcsh has on Mac OS X.
YMMV
|
|
-DU-...etc...
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|