LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2010, 04:16 AM   #1
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Rep: Reputation: 30
How to schedule for a repeated task?


Dear All
I need to schedule for a repeated task on my Linux, as the followings:
-) Telnet to a remote node
-) Issue a command
-) Capture the output in a log
-) Logout from Telnet
-) Wait for a prescribed time interval
-) Then redo , but append the subsequent output in just on file
Can you please let me know which options do we have to write such a task?
Thank you
 
Old 05-02-2010, 04:35 AM   #2
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
use cron.
you can write a shell script to do the work, and let cron take care of the scheduling.
there are some nice gui applications that deal with cron if you don't want to use it manualy

but i have a hunch that i got your question wrong.
i assume that you know how to perform all the commands above for the command line...
if you don't, write which and i'll try to help
 
Old 05-02-2010, 04:36 AM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

There are several ways to do what you want, but first of all let me ask you, why would you use telnet? It's very insecure, sends its data in plain text, and so on. Why not use ssh instead? Once you made your choice you can easily write a bash script to perform the necessary task and have it run using cron for example. Some good resources on Bash can be found here:
Bash Beginners Guide
Advanced Bash Scripting Guide

You'll have to put in some work of your own, you'll not find anyone here that'll give you a ready made solution. Show us what you have got already and where it fails, and we'll help you solve the problems you encounter.

Kind regards,

Eric
 
Old 05-03-2010, 11:40 PM   #4
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Original Poster
Rep: Reputation: 30
>plain text, and so on. Why not use ssh instead? Once you made your >choice you can easily write a bash script to perform the necessary task
I want to make use of ssh for accomplishing this task . The remote node is now an Red Hat 9 . I tried as the followings :
-First, ssh to the remote machine and then logout .
- Second , generate a key :
- #ssh-keygen t dsa
- Third , copy the public key to the remote machine :
- #scp ~/.ssh/id_dsa.pub username@remote.server:.ssh/authorized_keys
- Select your appropriate passphrase
But it didn't get through. Actually I wanted to enable it to schedule my task as the following:
#ssh username@remote.server somecommand
Please help me to solve the problem.
Thank you
 
Old 05-04-2010, 01:20 AM   #5
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Original Poster
Rep: Reputation: 30
I found how to enable it but it is asking for entering the 'pass phrase' every time I ssh to it. How can I disable this?
 
Old 05-04-2010, 01:43 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

You have two possible solutions for that, one is to work with the SSL keys.

CD into directory /root/.ssh. First create the key-pair that will be used to authenticate.
Code:
ssh-keygen -t dsa -b 1024
the output is shown below
Code:
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Hit <enter> here to accecpt the proposed name or type in a new filename to use.
Code:
Enter passphrase (empty for no passphrase):
It's very important to just press enter here to create a key with an empty password. If you don't do this and type in a password the program will fail because it will ask for a password every time it launches.
Code:
Enter same passphrase again:
Hit enter again to confirm the empty password.

Code:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ab:03:b9:9c:61:58:f1:70:f4:58:6a:0c:5e:b3:92:b4 root@srvtradupg
The key's randomart image is:
+--[ DSA 1024]----+
|    o.+ .        |
|   oo*.B         |
|    E=* .        |
|    .o.          |
|   o .  S        |
|  . =    .       |
|   o =  .        |
|    + ..         |
|      ..         |
+-----------------+
this is the final output and the key's are generated. The example above is just that, an example and always is different. It's a random key that will be compared between the keypair to authenticate.

If you followed the steps as indicated above you'll have two files in your /root/.ssh directory, named id_dsa and id_dsa.pub. Copy the id_dsa.pub file over to the second server SERVER2 in the /root/.ssh directory.

Login on the second server and CD into the /root/.ssh directory. Perform the following command to add the key to the authorized_keys file.
Code:
cat id_dsa.pub >> authorized_keys
From now on you can open an ssh tunnel from SERVER1 to SERVER2 without the need for a password. Try it out using the following command.
Code:
ssh root@SERVER2
If all is well you get the prompt at SERVER2 without having to enter a password.

The other option is to use a tool called sshpass, download and install the program to your server and in your script or from the command line use this to connect without having to type your password.
Code:
sshpass -p 'thepassword' ssh root@SERVER2 'yourcommand'
Kind regards,

Eric
 
Old 05-04-2010, 02:44 AM   #7
hadimotamedi
Member
 
Registered: Aug 2009
Posts: 228

Original Poster
Rep: Reputation: 30
Thank you very much for your help. At now, with the aid of your comment, I can ssh to my remote node without asking for entering password.
Thank you again
 
Old 05-04-2010, 02:58 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

I'm glad it worked out. Enjoy Linux.

If you consider your question/problem solved then please mark this thread as such using the Thread Tools.

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shut down time in time schedule task fa_khan50 Linux - Newbie 3 02-08-2008 01:17 PM
shut down time in schedule task fa_khan50 Linux - Server 3 02-08-2008 11:09 AM
How to schedule *interactive* task with at or cron fast_rizwaan Linux - Newbie 4 09-09-2005 06:26 PM
Schedule a task ! L1nuxbug Linux - Networking 4 03-02-2005 07:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration