- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Calling Telnet from a Script called from Cron
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:13 AM
тАО08-28-2008 05:13 AM
Scripting is something rare to non-existent in our environment, so I apologize in advance.
I've searched several sites, forums etc, but I'm not able to put the 2 and 2 together on this.
What we have is a script that runs at regular intervals and looks for a file in a folder. When the file is there, we have a While/Do that calls a 2nd script that will telnet into itself, and issue keyboard commands (echo) to log in and process the file.
When fired off manually, the 1st script sees the new file, calls the 2nd script and processes the file perfectly (well it works anyway...LOL).
When we have the execution ran from the cron process, the log (Cron) doesn't show anything of real value. The 1st script files off, calls the 2nd script but I think I'm missing something, since it doesn't actually run. The first script does finish as it moved the file to the "processed" subfolder. I know this is really basic stuff, but any help is greatly appreciated!
Here is the 2nd script (edited for content):
( echo open myself
sleep 2
echo login
sleep 1
echo password
sleep 1
echo more commands
echo log out of application
) | telnet
I know, I know, color me stupid. Having a real brain fart today.
Thanks a million!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:19 AM
тАО08-28-2008 05:19 AM
Re: Calling Telnet from a Script called from Cron
You must remember that the environment in cron is very sparse. Your /etc/profile and ~/.profile do NOT get sourced so any PATH or other environment variables you have when logged in are NOT available.
If you are referencing any variables in your scripts, double check and make sure those variables are defined in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:27 AM
тАО08-28-2008 05:27 AM
Re: Calling Telnet from a Script called from Cron
I'm purely passing keystrokes to the telnet session. I'm not using any variables (so far).
I keep finding data that points to environment as you described, but what would I actually need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:28 AM
тАО08-28-2008 05:28 AM
Re: Calling Telnet from a Script called from Cron
How about remsh or ssh and supply the commands.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:30 AM
тАО08-28-2008 05:30 AM
Re: Calling Telnet from a Script called from Cron
Can you tell me how did you set cron entry here...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:35 AM
тАО08-28-2008 05:35 AM
Re: Calling Telnet from a Script called from Cron
From the contab -l :
0,5,10,15,20,25,30 12-20 * * * /usr/ndm/tmp/dir/./File1.scr > /usr/ndm/tmp/dir/File1.log
The log files are empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:49 AM
тАО08-28-2008 05:49 AM
Re: Calling Telnet from a Script called from Cron
cd /usr/ndm/dir1/Inbound
ls file1*.csv | while read file
do
/usr/ndm/tmp/dir/./Script2.scr
mv file1*.csv /usr/ndm/dir1/Inbound/done/
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 05:54 AM
тАО08-28-2008 05:54 AM
Re: Calling Telnet from a Script called from Cron
Can you attach both scripts here...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 06:08 AM
тАО08-28-2008 06:08 AM
Re: Calling Telnet from a Script called from Cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 06:09 AM
тАО08-28-2008 06:09 AM
Re: Calling Telnet from a Script called from Cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 06:09 AM
тАО08-28-2008 06:09 AM
Re: Calling Telnet from a Script called from Cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 06:50 AM
тАО08-28-2008 06:50 AM
Re: Calling Telnet from a Script called from Cron
telnet is gonna have issues, as you don't have a tty when running via cron.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 06:52 AM
тАО08-28-2008 06:52 AM
Re: Calling Telnet from a Script called from Cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 07:04 AM
тАО08-28-2008 07:04 AM
Re: Calling Telnet from a Script called from Cron
I agree with Tim and OldSchool --- you should look at 'remsh' or 'ssh'. It appears that you are trying to invoke a 'telnet' session simply to provide connectivity to another server and do a simple script involving selecting and renaming some files. This is what 'remsh' or 'ssh' is designed to offer.
Too, in your first script you have:
/usr/ndm/tmp/dir/./Script2.scr
That makes no sense unless it is a posting error.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 07:17 AM
тАО08-28-2008 07:17 AM
Re: Calling Telnet from a Script called from Cron
If I used something like ssh, is the format the same as the telnet session?
If I was able to call the application directly without using telnet, how can I pass the keystrokes? Can I still use Echo and sleep? Does the list of commands need to be in parenthesis?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 07:50 AM
тАО08-28-2008 07:50 AM
Re: Calling Telnet from a Script called from Cron
Using 'ssh' or 'remsh' could be as simple as this (example) to list files on a remote server:
# ssh remoteboxt 'ls /home/jrf/*.log|while read FILE;do echo ${FILE};done'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 08:29 AM
тАО08-28-2008 08:29 AM
Re: Calling Telnet from a Script called from Cron
Thanks a million! I am light years ahead. Only hurdle I have left is passing the password when make the SSH connection. For some reason the echo command isn't passing it. Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 08:55 AM
тАО08-28-2008 08:55 AM
SolutionSetup SSH public keys. See Matti's directions in this thread --- he does a nice job of describing the simple procedure:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1254688
I'm not sure what you mean by "...the echo command isn't passing". If you wanted to do:
# ssh remotebox 'ls /home/jrf/*.log|while read FILE;do echo ${FILE} > /var/tmp/results;done'
...then you coult retrieve the results back to your local server with:
# scp remotebox:/var/tmp/results /home/jrf/results
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2008 09:24 AM
тАО08-28-2008 09:24 AM
Re: Calling Telnet from a Script called from Cron
I am at 100% success.
When I tried to test, I was getting a password prompt, but took your advice and VOILA!
Again, thanks to everyon's feedback, I was not only able to get my problem solved, but learn a ton in the process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 09:51 AM
тАО09-02-2008 09:51 AM
Re: Calling Telnet from a Script called from Cron
cd /usr/ndm/dir1/Inbound
ls file1*.csv | while read file
do
/usr/ndm/tmp/dir/./Script2.scr
mv file1*.csv /usr/ndm/dir1/Inbound/done/
done
"
"/usr/ndm/tmp/dir/./Script2.scr"
As noted previously, this makes no sense. What do you think the "." represents? This should probably be something like:
/usr/ndm/tmp/dir/Script2.scr
As I noted before, typically this would be set up in the a crontab on the "other" machine. Logging in or rexec'ing or ssh is just more overhead. It is simple enough to check for the existance of files of that name pattern and procede or not based on those results. I can see the utility of machineA:scriptA running scriptB on machineB if scriptB depends upon something that scriptA does, but that isn't clear in this case.
In any case, be aware that it is possible for "file1*.csv" to be different in the two invocations. You might consider storing the result in a variable, and then processing that variable.
What happens if another process adds "file1abc.csv" after the "ls" runs and before/during Script2.scr's execution. The "mv" will see fileabc.csv and move it, but it won't have been processed. Such errors can be a headache to find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 08:00 PM
тАО09-02-2008 08:00 PM
Re: Calling Telnet from a Script called from Cron
Well the variable in question is $file.
ls file1*.csv | while read file; do
...
mv $file /usr/ndm/dir1/Inbound/done/
done
>What happens if another process adds "file1abc.csv" after the "ls" runs
If you use $file above, you'll catch it next time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2008 10:23 AM
тАО09-03-2008 10:23 AM
Re: Calling Telnet from a Script called from Cron
I wasn't paying enough attention to
file*, read ... file, and $file...
On the other hand, the names used don't exactly thrill me either...but thats another story.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2008 10:37 AM
тАО09-03-2008 10:37 AM
Re: Calling Telnet from a Script called from Cron
2: ls file1*.csv | while read file
3: do
4: /usr/ndm/tmp/dir/./Script2.scr
5: mv file1*.csv /usr/ndm/dir1/Inbound/done/
6: done
Dennis,
My point was that this is just plain wrong...your fix is indeed correct.
If this is indeed an iterative process (multiple files being processed 1 at a time by the script in line 4) the results won't be as expected, especially if Script2 relys on $file.
In the example presented by the OP, he will set variable "file". Script2 runs and presumably processes $file. The move, as listed, would move the 2nd and subsequent file1*.csv "out from under" the the loop. "file" in line 2 gets set a second time, but by then that file is no longer in the directory and everything falls on its face.
Scott