Running a remote script with automatic options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a remote script with automatic options
# 1  
Old 12-26-2016
Running a remote script with automatic options

I'm trying to run a script that will remotely copy another script to remote host and run copied script to remote server with automatic options-

Code:
#! /bin/bash

HOSTNAME="1 2"
for HOST in $HOSTNAME;
do
        scp diskFrag.sh login@$HOST:/home/login
        sleep 30
        ssh login@$HOST chmod 777 /home/login/diskFrag.sh
        sleep 10
#        ssh login@$HOST /home/login/diskFrag.sh
        ssh login@$HOST echo "n e 1 1 +40G w y" | /home/login/diskFrag.sh
#        ssh login@$HOST printf 'n\ne\n1\n1\n+40\nw\ny' | /home/login/diskFrag.sh
        sleep 2
done

exit 0

This script I'm trying to copy and run it on another remote host-

Code:
#! /bin/bash

sudo su root

DELAY=3

fdisk -l
sleep $DELAY
fdisk /dev/sdb
sleep $DELAY
mkfs -t ext4 /dev/sdb
sleep $DELAY
mkdir /data
sleep $DELAY
mount -t ext4 /dev/sdb /data
sleep $DELAY
echo "/dev/sdb            /data       ext4      defaults         0 0" >> /etc/fstab
sleep $DELAY
mount -a
sleep $DELAY
df -T

exit 0

Auto options are not working given in first code -
Code:
ssh login@$HOST echo "n e 1 1 +40G w y" | /home/login/diskFrag.sh

Please advise some smooth way or rectification in the script to achieve it.
# 2  
Old 12-26-2016
I can only strongly discourage you from "automatically" tampering with any disk layouts / file systems! Any unexpected / unintended behaviour may result in disasterous results! On top, tasks like these won't usually be done umpteen times a day, so the value of automation might be dubious.

For your actual question: the input seems to be for fdisk to create a new partition and write it. But: the local shell will interpret the redirection operator and run the script locally; on the remote host just the echo command will executed and output to stdout i.e. the terminal.
- try enclosing the entire command list in double quotes.
- supply the fdisk commands as positional parameters and in the script echo them into fdisk.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-26-2016
/home/login/diskFrag.sh needs to change.

First off, there are no read statements in the script. When you echo to a script via a pipe it has to read from stdin what you echo.

Second, there is no place in the script that uses any options. It looks like you are adding the device /dev/sdb and mounting it as a disk. None of those commands are using any other "options" that I can see.

So, you are sending commands to a "deaf" script that would not "know how" to do anything with those options anyway.

Please provide us with what you want to have that script do and together we can work out options. As things stand there is no way to know what you want.

RudiC's commnets are spot on.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running options in bash script

Hello UNIX & Linux Forums community! Long time Linux daily user hobbyist, new to shell scripting.... I'm working on a script that does all the "work" in one script, and makes calls to a second script to display info to the user via mostly expanding variables in heredocs. I'm contemplating... (6 Replies)
Discussion started by: Cody Learner
6 Replies

2. Shell Programming and Scripting

Running script on remote server

Hi All, I need to run a ksh script on around 200 servers(consisting of AIX,LInux,HP-UX,Solaris). The script is there in the /tmp directory of all the servers. I want want to execute the script in background on the respective servers and then exit from there. I have written something like below:... (8 Replies)
Discussion started by: proactiveaditya
8 Replies

3. UNIX for Dummies Questions & Answers

Display problem when running a remote script

Hi, Quick question, someone will hopefully be able to stop me from :wall:. I currently have a script which calls a script on a remote machine and captures the stdout to a file: ssh <user>@<server> > output 2>/dev/null <<_EOF /path/script.ksh _EOF This runs the script but the... (4 Replies)
Discussion started by: chris01010
4 Replies

4. UNIX for Advanced & Expert Users

Script running on remote machine - How ??

Hi All, This was an interview question " There is a clean-up shell-script in one UNIX machine and it is connected to 100 other UNIX machines. Howe can we run the script on all the 100 machines without ftping/copying the script to target machines ? I was unable to answer, please answer if... (5 Replies)
Discussion started by: coolbhai
5 Replies

5. UNIX for Dummies Questions & Answers

Problems running script on remote Terminal

Hi, I'm new here so please excuse any stupidity that occurs in my post :P My situation: Have a java program which I have to run a ridiculous amount of times and put the output data into a text file. Thought the easiest way to do this would be to delve into the world of scripts. I am at home... (1 Reply)
Discussion started by: lozyness
1 Replies

6. Shell Programming and Scripting

Problem with running the remote script

Hi All, I am running a script which is present on remote machine using ssh command. the remote script is failing when try to load a property file. It says file does not exist. Any idea what should be the problem for this. Thanks Supriya. (7 Replies)
Discussion started by: supriyabv
7 Replies

7. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

8. UNIX for Advanced & Expert Users

Running script on remote machine

if i have a script in my system which i need to run on remote system using ssh, how shall i do it? One easy way to to first scp it to remote machine and then run it on remote machine using ssh. Is there any one step way to do it. Preferably one in which i should give password only once (3 Replies)
Discussion started by: vickylife
3 Replies

9. Shell Programming and Scripting

Running a Script in a Remote server

I am trying to write a script that would let me run a command in a remote server using ssh. scriptA: (dcm2nii is a command that only works on the other server) dcm2nii a b c scriptB: (I run this one on the current server) ssh -X otherserver /home/abc/Desktop/scriptA But when I do ... (2 Replies)
Discussion started by: ZeroGPX
2 Replies

10. Shell Programming and Scripting

running a script on remote server.

I need to run a script on a remote server from my ksh script. The issue I'm having is that I need to logon to the remote server as a different user. (see the following) logged on to server 1 as adsmgr neet to log on to server 2 as odemgr run passwd_util.ksh Thanks in advance. (1 Reply)
Discussion started by: whited05
1 Replies
Login or Register to Ask a Question