|
Answer» Hello All,
I am trying excute a a UNIX script in a regular intervals for this i have used telnet command in a batch file to connect to remote server. But i was unable to do that.
Could some one in the group share your thoughts on how to use a telnet commands in a batch file so that with out any manual intervention in can execute the script.
Thanks VishHave you tried the Unix crontab?I use HP-UX at work ... below is the man page of the crontab. It should be of some help to you.
crontab(1) crontab(1)
NAME crontab - user job file scheduler
SYNOPSIS crontab [file]
crontab -e [username]
crontab -l [username]
crontab -r [username]
DESCRIPTION The crontab command manages a crontab file for the user. You can use a crontab file to schedule jobs that are executed automatically by cron (see cron(1M)) on a regular basis. The command has four forms:
crontab [file] Create or replace your crontab file by copying the specified file, or standard input if file is omitted or - is specified as file , into the crontab directory, /var/spool/cron/crontabs. The name of your crontab file in the crontab directory is the same as your effective user name.
crontab -e [username] Edit a copy of the user's crontab file, or create an empty file to edit if the crontab file does not exist. When editing is complete, the file will be copied into the crontab directory as the user's crontab file.
crontab -l [username] Lists the user's crontab file.
crontab -r [username] Remove the user's crontab file from the crontab directory.
Only a privileged user can use username following the -e, -l, or -r options, to edit, list, or remove the crontab file of the specified user.
The entries in a crontab file are lines of six fields each. The fields are separated by spaces or tabs. The lines have the following format:
minute hour monthday month weekday command
The first five are integer patterns that specify when the sixth field, command, should be executed. They can have the following ranges of values:
minute The minute of the hour, 0-59
hour The hour of the day, 0-23
monthday The day of the month, 1-31
month The month of the year, 1-12
weekday The day of the week, 0-6, 0=Sunday
Each pattern can be either an asterisk (*), meaning all legal values, or a list of elements separated by commas. An element is either a number in the ranges shown above, or two numbers in the range separated by a hyphen (meaning an inclusive range). Note that the specification of days can be made in two fields: monthday and weekday. If both are specified in an entry, they are cumulative. For example,
0 0 1,15 * 1 command
runs command at midnight on the first and fifteenth of each month, as well as every Monday. To specify days in only one field, set the other field to asterisk (*). For example,
0 0 * * 1 command
runs command only on Mondays.
The sixth field, command (the balance of a line including blanks in a crontab file), is a string that is executed by the shell at the specified times. A percent character (%) in this field (unless escaped by a backslash (\)) is translated to a newline character, dividing the field into "lines". Only the first "line" (up to a % or end-of-line) of the command field is executed by the shell. Any other "lines" are made available to the command as standard input.
Blank lines and those whose first non-blank character is # will be ignored.
cron invokes the command from the user's HOME directory with the POSIX shell, (/usr/bin/sh). It runs in the c queue (see queuedefs(4)).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory LOGNAME=user's-login-id PATH=/usr/bin:/usr/sbin:. SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use crontab if your name does not appear in the file /usr/lib/cron/cron.deny. If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.
WARNINGS Be sure to redirect the standard output and standard error from commands. If this is not done, any generated standard output or standard error is mailed to the user.
FILES /var/adm/cron Main cron directory /var/adm/cron/cron.allow List of allowed users /var/adm/cron/cron..deny List of denied users /var/adm/cron/log Accounting information /var/spool/cron/crontabs Dir containing crontab filesQuote Hello All,
I am trying excute a a unix script in a regular intervals for this i have used telnet command in a batch file to connect to remote server. But i was unable to do that.
Could some one in the group share your thoughts on how to use a telnet commands in a batch file so that with out any manual intervention in can execute the script.
Thanks Vish i assume you want to execute telnet commands from a Windows machine to a unix machine to execute a Unix script. You can use PERL's Net::Telnet module to do it. Look at http://www.perlfect.com/articles/telnet.shtml for pointers. Or you can download a third parth telnet client to do that. Hello All,
Many thanks for your postings. My requirment is i am trying to connect remote unix server using Telnet command in a batch file
test.bat
telnet -f C:\telnet_logfile.log brussels.bbx.com < C:\TelnetCommand.txt
I have created the above command in a batch file and i have used TelnetCommand.txt as a input which stores the User id and password of the remote server and the commands to execute the unix script.
TelnetCommand.txt userid password cd /home/pidurpi/srcfiles sample.sh
Could some one please tell me is there other way to connect to unix from a batch file and RUN the unix scripts?
Thanks, Vish
|