Can BASH execute commands on a remote server when the commands are embedded in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can BASH execute commands on a remote server when the commands are embedded in shell
# 1  
Old 12-03-2008
Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config.
I am not sure if I can do this with BASH scripting.
I have set up password less login by adding my public key to authorized_keys file, it works.
I am a little bewildered about whether I can execute commands on the remote server from within my BASH script.
I am thinking that It would be necessary to use expect. I have looked at expect and am not sure I want to go there.

I currently have
# ./copy_to_server httpd.conf.new /etc/httpd/conf/ 192.168.1.100
#/bin/bash
FILE1=$1
FILE2=$2
FILE3=$3
FILE4=$4
FILE5=$5
FILE6=$6



if [ ! -f "$FILE3" ]; then
scp $FILE1 $FILE3:$FILE2
else
echo "$FILE3 is not up"
fi

##########
So the file is on the remote server, now I want to move around some exsting files.

Now I am unsure how to set up to check for the existing httpd.conf and move it around on the remote server using BASH.
[ -f /etc/httpd/conf/httpd.conf ]
mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bk_up
mv /etc/httpd/conf/httpd.conf.new /etc/httpd/conf/httpd.conf

And then log off

Can BASH do this on its own?

I thought that one way around this would be to create a cron job to check /etc/httpd/conf/ dir for a new file
when it finds httpd.conf.new it could move over the old and move in the new.

So now I am curious is executing multiple commands on a remote server via bash possible? and then logging off.

Any suggestions are appreciated.

Last edited by bash_in_my_head; 12-04-2008 at 10:50 PM..
# 2  
Old 12-04-2008
You should start reading about ssh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Not able to execute standard commands on centos 7 server

I am not able to run basic commands on my centos 7 server. The PATH variable looks correct I think. I have not seen this before and not sure what to do next. Thank you :). # cd /usr/bin # ls bash: ls: command not found... Similar command is: 'lz' nano ~/.bashrc bash: nano: command not... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. AIX

Nim server "Unable to execute remote client commands"

Hello, What is its mean? Could you please help me? Best regards, root@nimserver:/> nimadm -j nimadmvg -c dev4 -s spot1 -l lpp_source1 -d "hdisk7" -Y Initializing the NIM master. Initializing NIM client dev4. 0042-006 c_rsh: (exec_nimsh_cmd) exec_cmd Error 0 poll: setup failure... (2 Replies)
Discussion started by: getrue
2 Replies

3. Shell Programming and Scripting

How to execute commands on remote server using expect script?

I need to copy python script file to around 100 servers using expect script. 1. Copy script to my user home first(/home/myhome) on each remote server 2. change permissions on copied file to 766. 3. sudo to appuser1 account on remote server. copy script file from my user home to /usr/bin/... (1 Reply)
Discussion started by: kchinnam
1 Replies

4. Shell Programming and Scripting

Shell script help to execute ssh remote commands

Hi, The below command is not giving me the count , Can somebody help me in re-writing this pls . Proc_Exist=`ssh -q -o "BatchMode=yes" -o "PasswordAuthentication=no" $OAUSER@${Primary_Node} ps -ef | grep -v grep | grep "${ICM_Proc}" |wc -l ` Also the same problem with below... (13 Replies)
Discussion started by: Y.balakrishna
13 Replies

5. Shell Programming and Scripting

Login to remote host and execute commands

Hi, i want to write script where it will login into 50 hosts and if login is successful it print message "login to host1 is successful" if not it should print message "Not able to login to host1". once connection to the host is succesful it should fire df command to check filesystem if df is... (3 Replies)
Discussion started by: amru8810
3 Replies

6. Shell Programming and Scripting

Shell: How to execute commands from another file?

I made a configuration file for my shell script in that all the values that the shell scipt needs, are defined, but I don't know how to let the shell script use those defined variables. Thank you for your help :) (3 Replies)
Discussion started by: Alkali
3 Replies

7. Shell Programming and Scripting

execute remote commands with rsh

Hi, I earlier determined I cannot use FTP to execute remote commands on a server. My problem, I need to use a second server to get/put files via ftp onto my primary server and various tertiary servers. my server(A) ---> server (B) ----> server blah(c), server balh(C) I cannot directly... (1 Reply)
Discussion started by: mcclunyboy
1 Replies

8. UNIX for Dummies Questions & Answers

Sending commands to a remote server

Hi I have managed to connect to a remote server via ssh, but nothing will actually send through to the remote server screen through my script...it waits until i am back to the main terminal before it outputs anything. Can anyone tell me how to get commands to send through to the remote server?... (4 Replies)
Discussion started by: Hopper_no1
4 Replies

9. Shell Programming and Scripting

Execute ssh commands through bash script

Hi all! I am trying to write a script that will check if a certain directory is available at several different nodes and then do stuff in it ..... On the beginning of the script I give as a variable the directory and the number of the nodes and then I loop like this: for... (3 Replies)
Discussion started by: idet2
3 Replies

10. Shell Programming and Scripting

Execute commands from script in current bash session

I have a file as follows: cat /etc/mxg/ssh-hostsmx.example1.com.au:2225 mx2.example2.com.au:2225 mx.example3.com.au:2225 mail.example4.com.au:2225 mail.example5.org.au:2225 mail.example6.com.au:2225I want to dynamically create aliases for quick access to these servers from bash. I wrote... (4 Replies)
Discussion started by: jelloir
4 Replies
Login or Register to Ask a Question

Featured Tech Videos