Visit Our UNIX and Linux User Community


How to run a shell script on a remote host using ftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run a shell script on a remote host using ftp
# 1  
Old 07-16-2012
How to run a shell script on a remote host using ftp

Hi,
is there a way I can run a shell script through ftp on a remote host? The remote host doesn't have ssh running so I can't use ssh.
# 2  
Old 07-16-2012
Is telnet running on the remote host?
# 3  
Old 07-16-2012
Perhaps something with
scheduled cron task
the task checks for the existence of a file
(this could be ftp'ed to the remote system)
then a script is executed
# 4  
Old 07-16-2012
Quote:
Originally Posted by jim mcnamara
Is telnet running on the remote host?
telnet is running, i just tried the following telnet script on it, it worked but there is code in my ksh script after the telnet commands, and that code doesn't execute, as if the script is unable to get out of telnet:

Code:
 
#!usr/bin/ksh
 
(sleep 2
echo user
sleep 1
echo pass
sleep 2
echo "/path/to/script.ksh"
sleep 1
echo "exit") | telnet host1
#program freezes here i think
 
#more code to execute

---------- Post updated at 11:21 AM ---------- Previous update was at 10:42 AM ----------

Quote:
Originally Posted by joeyg
Perhaps something with
scheduled cron task
the task checks for the existence of a file
(this could be ftp'ed to the remote system)
then a script is executed
I don't have experience with cron but doesn't that just run a script at certain time intervals? I want to run the script whenever I prompt it to run.

Last edited by mrskittles99; 07-16-2012 at 11:48 AM..
# 5  
Old 07-16-2012
You can run the watch command on the remote machine and while it is running the script will be executed. The script can be multiline:

Execute the script on the remote machine every 60 seconds
Code:
echo > mycommands.sh
watch -n60 "chmod +x timedcommand.sh && ./timedcommand.sh"

Remotely overwrite the mycommands.sh file via ftp.

You can upload an empty file to stop commands.
# 6  
Old 07-16-2012
Quote:
Originally Posted by Tribe
You can run the watch command on the remote machine and while it is running the script will be executed. The script can be multiline:

Execute the script on the remote machine every 60 seconds
Code:
echo > mycommands.sh
watch -n60 "chmod +x timedcommand.sh && ./timedcommand.sh"

Remotely overwrite the mycommands.sh file via ftp.

You can upload an empty file to stop commands.
I'm not supposed to be running the script that often, is there a different way to do this? I also have remsh on the host. can remsh run scripts?
# 7  
Old 07-16-2012
remsh requires Kerberos 5 authentication and requires that the local user ID is not the root user. You specified to use only ftp not remote shells.

The watch command has the disadvantage that if the computer reboots you lose the command. You can use any well known scheduler for that cases.

Check here at cron:
http://www.garron.me/linux/run-cronj...tes-hours.html

---------- Post updated at 11:22 AM ---------- Previous update was at 10:52 AM ----------

There is another way you can do it: test permanently on host if a certain file exists, and when it does run the command once.

So you re-upload the run.txt file again for each time you want to run mycommand and even you can change the command for the next time. If for some reason the command fails the file failed.txt will be generated and you can see it from ftp.

On host:
Code:
echo "my command" > mycommand.sh

Code:
watch -n10 "if test -e run.txt ; then chmod +x mycommand.sh && ./mycommand.sh && rm run.txt || rm run.txt && echo > failed.txt ; fi"

-------------
Remote:
Code:
 ftp put run.txt run.txt

OR
Local:
Code:
echo > run.txt


Last edited by Tribe; 07-16-2012 at 01:51 PM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #578
Difficulty: Medium
Lists are ordered collections that are essentially static arrays.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies

2. Shell Programming and Scripting

Run awk command on remote host

I have below command to check for error logs from last 24 hours from the file : /var/log/messages/ The command is working fine on the local host. sudo awk -F - -vDT="$(date --date="24 hours ago" "+%b %_d %H:%M:%S")" ' DT < $1' /var/log/messages | egrep -i "error|fail" I want to run the... (8 Replies)
Discussion started by: rahul2662
8 Replies

3. Shell Programming and Scripting

Run script on remote host

Hi friends, I have two servers. Server A and B. I want to run one script on server A by logging in to server B. Can anyone provide me code for this.? I tried it by using following ssh username@serverA ./script Then it prompt me the password. I give correct password of the server A. but it... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

4. Shell Programming and Scripting

HTML Code to Run a Script from Remote Unix Host

Hi All, Noticed few posts around this but coudnt get exatcly what i wanted. Thanks for your help again. I have a script running on a remote machine and i normally ssh from putty and run the script manually. Is there anyway that i can write an HTML Code with a button so taht when I Click... (1 Reply)
Discussion started by: robinbannis
1 Replies

5. UNIX for Dummies Questions & Answers

Run a script on remote host

Hi, I wish to run a script located on a remote host machineB from machineA. I am using ssh and running the below on machineA. However, the ssh does not seem to work and freezes at ssh -l wlsadmin machineB -v Sun_SSH_1.1.2, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1: Reading... (9 Replies)
Discussion started by: shifahim
9 Replies

6. Shell Programming and Scripting

Executing scipts after logging into a remote host using shell script

Hi All, Sorry if it is a duplicate post. I have not got any reference about this anywhere. I looked at the posts described in SSH - Passing Unix login passwords through shell scripts - Linux / UNIX Forum and it helped me till the point to connect to the host and executing the basic commands.... (3 Replies)
Discussion started by: RSC1985
3 Replies

7. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

8. Shell Programming and Scripting

Run Shell Script on Remote System

I honestly tried searching for this in this forum and in google. Maybe I found the answer but didn't even realized it. I would like to run shell script thats on my machine that collects the hostname and IP address from the remote system and sends the output to my machine. I'm not sure if need... (2 Replies)
Discussion started by: elbombillo
2 Replies

9. Shell Programming and Scripting

How can my unix shell script automatically connect to remote host?

How can my unix shell script automatically connect to remote host? Assume that there is a remote host called "rhost". When I connect to that host i give the command "telnet rhost". It then asks me for my id and password. Once i give it connects there. I want to automate these steps. I want... (8 Replies)
Discussion started by: digdarshan
8 Replies

10. IP Networking

FTP - Connection Closed By Remote Host

Hi, I am having a problem with our AIX 4.3.3 Server accessing FTP. The error is " Connection Closed By Remote Host". Scenario: Since i put a default gateway on the server FTP connection is having a problem but when i remove the default gateway it will works fine.. Is there any way not... (1 Reply)
Discussion started by: mouglybean
1 Replies

Featured Tech Videos