LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron command (https://www.linuxquestions.org/questions/linux-newbie-8/cron-command-357624/)

alphamike 08-27-2005 07:11 PM

cron command
 
hi there....not just a new newbie...but a total newbie:)

i am trying to set a cron job on my web server, i know the format is in unix style


i have an ftp account that i want my webserver to access and then once accessed to simply delete a specific file

i know how to get the cron to contact the remote machine..i think

lets say the username is mike and the password is mike for the remote ftp account

some thing like this isnt it?

Code:

ftp://mike:mike@2##.1##.92.1##:21
the file i want to delete is located in the root of the ftp account.

i know the command for deleting a remote file is simply "delete". but i do not know who to structure the command. Any help would be appreciated

trickykid 08-27-2005 09:39 PM

If you have ssh enabled, your probably better off creating a quick script to remove the file by using ssh keys so you don't have to pass a password to the server.

Create the script:

Code:

#!/bin/bash
# Script to remove a file from remote server.

for machine in <hostname-here>
do
  ssh -i $machine /bin/rm /path/to/file
done

Make the script executable by doing: chmod +x <scriptname>

Then just add this to your crontab (the example would run at 2:20 AM daily):

Code:

20 2 * * * /path/to/script/created/above 1> /dev/null
man ssh to read more about how to setup ssh keys so it doesn't prompt for a password.

mhallbiai 08-28-2005 12:04 AM

Re: cron command
 
this should take care of it for you...
(NOTE: i am using your example so change it accordingly ;))

create ~/.netrc and change its permissions to rw only by you chmod 600 ~/.netrc if it does not already exist, otherwise just add the following anywhere in the file as long as it is above any 'default' line you have

in .netrc place this line
Code:

machine 2##.1##.82.1## login mike password mike
this should allow for auto-login. you can confirm this by running 'ftp 2##.1##.82.1##' if it logs you in without prompt for user/pass then continue

example script (script_name):
Code:

#!/bin/bash
# used to delete filename_to_delete from 2##.1##.82.1##
#
ftp << EOF
open 2##.1##.82.1##
delete filename_to_delete
bye
EOF

that should be it. make the script executable (chmod 700 script_name), then add it to cron.
confirm that it works from cli first. if it works when invoked from cli (./script_name) but not from cron then add . /etc/bashrc above the 'ftp << EOF' line and try again

hope this helps

[EDIT: i would agree with trickykid on using ssh if possible]


All times are GMT -5. The time now is 07:21 PM.