Shell script for remote servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for remote servers
# 8  
Old 07-22-2016
You are using the -n option, which means redirect stdin from /dev/null.
# 9  
Old 07-22-2016
The while lopp script:

Code:
set -x
#!/bin/ksh
while read servername  <&3
do
ssh -t $servername
uname -a
cd /home
echo "Enter Dir to be removed >"
read Dir
if [ -d "$Dir" ]
then
echo "$Dir exists"
else
echo "$Dir is not thre"
fi
logout
done 3< /tmp/list


It falls in the shell of the remove server.. if I exist , then it prompts for the options:

Code:
riker:/home/kampatel=> ./new_test.sh
+ 3< /tmp/list
+ read servername
+ 0<& 3
+ ssh -t server-1


 

HP-UX server-1 B.11.31 ia64 2459719568
 Server model: ia64 hp server Integrity Virtual Machine




You have mail.
You are superuser !

server-1:/root=>
server-1:/root=> exit
logout
Connection to server-1 closed.
+ uname -a
HP-UX server B.11.31 U ia64 0077323328 unlimited-user license
+ cd /home
+ echo Enter Dir to be removed >
Enter Dir to be removed >
+ read Dir
/home/kampatel/test
+ [ -d /home/kampatel/test ]
+ echo /home/kampatel/test is not thre
/home/kampatel/test is not thre
+ logout
./new_test.sh[16]: logout:  not found.
+ read servername
+ 0<& 3
+ ssh -t server-2

---------- Post updated at 06:18 AM ---------- Previous update was at 05:55 AM ----------

The problem is the above script just looks at the local servers path after i define the directory detail instead of looking into the remote server shell.. The script get executed, although it connects to the remote server it matches the path in the local servers and fails to remove the directories.

Last edited by RudiC; 07-22-2016 at 08:02 AM.. Reason: Added code tags.
# 10  
Old 07-22-2016
With the last script this is missing, as indicated in post #2:
Code:
"$(
  cat << EOF
    uname -a
echo "Enter the dir >"
    read path
if [ -d "$path" ]
then
echo "removing $path as per the input .."
rm $path
else
echo "no such file"
fi
exit
EOF
  )"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running set of commands in remote servers in shell script

Hi Wishing to all. I am very new joined in an organization as a unix system administrator. I need a help in preparing a script for a report. i have a file contains all of the linux/ubuntu servers line by line around 140 servers. vi servers.txt nh01 nh02 nh03 bh01 bh04 - - :wq (3 Replies)
Discussion started by: kumaraswamy
3 Replies

2. Shell Programming and Scripting

Remote login and running a script on multiple servers

Hi all, I am baffled on this. Solaris Irix system.:confused: I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek: ... (10 Replies)
Discussion started by: weddy
10 Replies

3. Shell Programming and Scripting

Bash script connect to remote servers and become root

Hi, I need a script that will connect to a list of servers and first sudo to root and then run a couple of commands. For security reasons, we can't setup ssh keys as root. Manually I have to login to a server as user and then sudo to root. It's not possible to use root@servername , because of... (8 Replies)
Discussion started by: misterx12345
8 Replies

4. Shell Programming and Scripting

Help with script to reach remote servers

new3=`cat /tmp/list3` for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'"); do export policy=`echo $pol`; su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done I am having trouble with this testscript as the file list3 has two names... (1 Reply)
Discussion started by: newbie2010
1 Replies

5. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

6. Solaris

Remote execution of a local script on multiple servers

So I have a scriptlet called solaris_command: for i in \ server1 server2 server3 do echo $i ssh $i $1 echo "" done I then use that as a command in multiple scripts to allow for data gathering for all virtual hosts in the environment thusly: solaris_command "cat... (3 Replies)
Discussion started by: os2mac
3 Replies

7. Shell Programming and Scripting

C shell scripting, check if link exists on remote servers

Hi, I'm new to C Shell programming. I'm trying to check if a sym link exists on remote server if not send email. I'm not having much luck. Can anyone help? Here is what I have written but it doesn't work. It tells me that my variable was not defined. Here is part of the script, the second... (0 Replies)
Discussion started by: CDi
0 Replies

8. Shell Programming and Scripting

Prevent wrong user from using shell script for multiple remote servers

Hi, I am running a shell script from a central server to multiple remote servers using the following code: application_check() { # Linux/UNIX box with ssh key based login SERVERS=`cat /tmp/server-details` # SSH User name USR="user" # create new file > /tmp/abc.log # connect... (2 Replies)
Discussion started by: mystition
2 Replies

9. UNIX for Dummies Questions & Answers

Running the same remote script on multiple servers

Experts, Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file. I struggled with this yesterday & finally that script is working now. Now, here is a scope creep and the script that I wrote for 1 remote... (2 Replies)
Discussion started by: OMLEELA
2 Replies

10. Shell Programming and Scripting

unix shell script which inserts some records into a file located in remote servers...

All, I need to write an unix shell script which inserts some records into a file located in remote servers. * Get the input from the user and insert according the first row. It should be in ascending order. 123451,XA,ABA 123452,XB,ABB 123453,XC,ABC 123455,XE,ABE 123456,XF,ABF 123458,XG,ABG... (2 Replies)
Discussion started by: techychap
2 Replies
Login or Register to Ask a Question