Cron ssh

In Terminal the following works:

ssh username@xxx.xxx.xxx.xxx

With CronniX, this same command does nothing. It will not trigger when scheduled nor when I try "Run Now".

The crontab I've created is for a user with admin level. What am I missing here?

QuickSilver Dual 1GHz Mac OS X (10.3.9)

Posted on Mar 26, 2006 10:20 PM

Reply
21 replies

Apr 5, 2006 3:20 PM in response to Redwoodtree

You have been so helpful, Red.

Are you saying that running this script by curl might pose a security risk? If so, how about wget?

The remote server is running wget. Using Terminal, I have been able to ssh into the server and then once logged in, use wget to run the php script and perform the import. But I cannot determine the syntax necessary to combine the ssh and wget into one single crontab task.

I don't have enough undertanding of cron syntax to make a conditional execution based on the success of a previous scp cron copy process. How would this be done?

QuickSilver Dual 1GHz

Apr 5, 2006 4:53 PM in response to Kenneth S Goff

No problem, what goes around comes around 🙂

It's not curl or wget specifically that is the problem. It's the idea that you can run a script through "port 80" that's unprotected. Hopefully your remote machine is behind a firewall and port 80 is blocked... or , if it's not blocked.. hopefully you have some way of keeping someone in japan from hitting your PHP script. Perhaps you could put in a .htaccess file in your web directory to only allow 127.0.0.1 (localhost) from hitting that script.

Making conditional executing in a cron process will be a little hard to describe in this forum. What I suggest is putting the commands in a shell script and call the shell script instead from the cron jon... take a look at scripts in any unix host in rc.d like /etc/rc.d or /etc/rc3.d or any of those startup type scripts, they always test for a file or for exit codes. It's just one place to check for sample scripts, you can find them on the net as well.

In short, I'd say, write a shell script that tests for the existence of the copied file, checks to see if the time is up-to-date (for example) then, issue the curl command from the script.

Hope it helps.

Apr 6, 2006 7:17 AM in response to Redwoodtree

Just adding in my 2p worth..

I'd really ( really) recommend doing the following when copying files over for automated use..

1.1 Create a checksum (My mac is currently dead, but I imagine you have a command like, sum or md5sum) of the file. (call it <file>.md5 for example)
1.2 scp the data file.
1.3 scp the sum.
1.4 your remote import script checks for the existence of a sum and data file.
1.5 Copy both Sum and Data file to a staging directory. Check the <file>.md5 sum matches the md5 of <file> (calculate the sum of <file> to <file>.check and cmp that with <file>.md5. If so, you have a complete file, and are ok to import.

This helps to prevent importing an incomplete file.

Apr 11, 2006 8:31 AM in response to Redwoodtree

Yes, that is a good idea. And other members of the Mac community could likely benefit from the details of this discussion.

The specifics of how to accomplish this are still hazy to me. The client system which generates the source file is running Mac OS X 10.3.9 Client OS while the server system uses Unix/Red Hat/Linux.

The shell script I'm currently trouble-shooting should do the following:

1 ) Copy the source file to the server using SCP.
2 ) Assign to a variable the result of MD5 on the source file.
3 ) Assign to a 2nd variable the result of MD5Sum on the destination file using SSH.
4 ) Use an if - then structure to compare the variable values.

I have discovered in Terminal that MD5 works on the client while MD5Sum works on the server and the results match. On the client MD5Sum within Terminal produces "md5sum: command not found." Attempting MD5 on the server produces a similar error.

My two concerns are testing and deployment.

Testing-

Can one cut and paste the entire contents of the shell script into Terminal or must one test just segments of the script?

If I put Var1=`md5 /path-to-file/file.txt`, Terminal complains that "Var1 is an undefined variable."

Also, can I use "echo" or some other mechanism to verify results while testing?

How can I trigger the entire script? Call it from a cron in CronniX and then "Run Now"?

Deployment-

Where should the shell script be located on the client OS X system? Should it be placed inside the hidden "/etc" folder?

Again, how should this shell script be triggered? Does one call it from a cron? Using "Run Now" in CronniX "/usr/bin/open /path-to-file/file.txt" just opens the text file instead of executing the shell script.

QuickSilver Dual 1GHz

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Cron ssh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.