• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

Cron Job to login and run one command and logout

I am wanting to create a cron job on Fedora core 8 that logs into a 7 of our network devices, and runs one command that pushes the database backup to an ftp server, and then logs out. Can anyone help me with this? Thanks in advance
0
buckethead34
Asked:
buckethead34
  • 2
  • 2
  • 2
  • +1
1 Solution
 
omarfaridCommented:
please the below link on how to run ftp through crontab:

http://www.experts-exchange.com/OS/Linux/Q_23357010.html
0
 
Deepak KosarajuSr. Monitoring Architect - Nagios/Op5 SME - ConsultantCommented:
I need more details! logs u mean login, if so what type of login it is? I mostly recommend configure password less login if possible.
0
 
arrkerr1024Commented:
The easiest way to run a command on a remote server is to use ssh.

In order to log in with out a password, you need to have the public key from the source machine in the authorized_hosts file on the target machine.

On the source machine (the machine running the command) see if you have ~/.ssh/id_dsa.pub or ~/.ssh/id_rsa.pub.  Those are public SSH keys.  If not, run "ssh-keygen -t dsa", which will create ~/.ssh/id_dsa.pub.

On the target machine create .ssh/authorized_keys and put the contents of the public key in that file.

Then simply run this from cron:
ssh target "command"

The very first time you run it you will have to accept the target machine's identity, so run it from the command line manually first.  That will make sure it works as well.

Good luck!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
buckethead34Author Commented:
I don't want the job to run ftp, sorry if I was vague. I want the cron job to telnet to a network device and run one command on the box and logout. I'm looking into adding some scripts to do it and expect being in the scripts etc.
0
 
arrkerr1024Commented:
My understanding is that you already have a command on the target machine that created a database dump and puts it on an FTP site.  You just want to be able to run that command from another machine's cron.

Do you also need help constructing the command that does the database dump and puts it on an FTP site?

These should be tackled, if possible, as two separate things.
1) create a script on the target machine that does the database dump and puts it on an ftp site
and
2) create a cron on the source machine that simply logs in to the target and executes the script

You could combine the two, if you need to.. but it'd be an ugly command.
0
 
buckethead34Author Commented:
Just number 2 is necessary a login and a command ran.
0
 
Deepak KosarajuSr. Monitoring Architect - Nagios/Op5 SME - ConsultantCommented:
If u have password less login then use can use the following for loop to login to each network devices and then run the following script.


#!/bin/bash
for i in `seq -w 7`;do echo test$i;ssh test$i"/usr/sbin/backup"; done

Open in new window

0
 
omarfaridCommented:
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now