Remote script skips "read" command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remote script skips "read" command
# 1  
Old 06-16-2010
Remote script skips "read" command

This script is supposed to display a file ( crontab ), ask the user if they wish to update the file, then it goes through an update routine.

Code:
#!/bin/bash
 FILE=/etc/crontab
  
 tail -5 $FILE
 
 echo -n "Does crontab need updating"
 read HOURS

...routines ....etc...

Runs locally fine but does not pause for input if I do:
Code:
ssh user@hostname < hours.sh

If I do this:
Code:
ssh user@hostname 'echo "type var";read var;echo $var'

It stops, get my input, then echoes var.

Ideas?

Thanks for reading!

Bubnoff

UPDATE: Here's something:
output from script:
Code:
stdin: is not a tty


Last edited by Bubnoff; 06-16-2010 at 05:19 PM..
# 2  
Old 06-16-2010
I'm not entirely sure of what you're asking here. Could you give another shot at explaining what the problem is?

If you're wondering why this doesn't work:

Code:
ssh user@hostname < hours.sh

and hours.sh contains your "echo..." commands then the reason is because when you redirect input into a command from a file, stdin is already opened, and ssh can't allocate a pseudo-tty when stdin is already opened.

My ssh version actually tells me this - "Pseudo-terminal will not be allocated because stdin is not a terminal."

The reason the second code sample works:
Code:
ssh user@hostname 'echo "type var";read var;echo $var'

is because you're passing the "echo" string as a command to run on the remote machine, and stdin is still free to be allocated to a local pseudo-tty.
# 3  
Old 06-16-2010
How would I get the script to catch my keyboard input with read when run remotely?

I've tried the '-t' and '-T' options to ssh with no success.
# 4  
Old 06-16-2010
I don't think you can both have stdin coming from the redirected file and also from the keyboard.

So, the solution is to put the script on the remote server, and execute it there.
# 5  
Old 06-16-2010
That'd work except there's a lot of machines to go through.

I wanted to do something to the effect:
Code:
for i in {10..55};do ssh root@10.10.18.$i < hours.sh;done

I don't exactly know what the crontab files will contain and writing a regex
for the possibilities seems a bit daunting. I could add a scp in there, but at that point I'm losing another step of automation.

I have to update an armada of machine's crontab files based on certain conditions. I was hoping to just "tail" the pertinent section, then have routines carry out actions based on my input ...rather than trying to have the script figure it out via regex. Especially since a regex would require more familiarity with the possibilities.

I may need to re-think this from the beginning and take a different tack.

So, outside of copying the script, this is not possible?

Thanks for your input.

---------- Post updated at 07:59 PM ---------- Previous update was at 07:12 PM ----------

From the ssh man page:

Code:
-t      Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be
 very useful, e.g. when implementing menu services. Multiple -t
             options force tty allocation, even if ssh has no local tty.

This almost works:
Code:
ssh -t -t root@10.10.17.25 < testread.sh

It does wait for me to type, but then stalls until <ctrl>-c.
# 6  
Old 06-17-2010
can't you do something like?

Code:
ssh user@hostname "$(cat hours.sh)"

This User Gave Thanks to a_programmer For This Post:
# 7  
Old 06-17-2010
As it turns out ...yes! It works ...but how? I "get" the $() and quoting construct but am wondering how this executes.
This isn't documented anywhere I looked. EDIT: Yes, I know that ssh executes stuff in quotes and am aware that $() is the
newer "backticks" construct. Specifically, how does this nested
construct with cat put the script on the correct tty/pseudo-tty to capture my input while executing my local script?

-- wait ---

I think I'm beginning to understand this ....

One note: This doesn't execute as expected:

Code:
read -p "Message from the beyond" VAR

You have to do this instead:
Code:
echo "Message from the beyond"
read VAR

Thanks dude!

Bub

Last edited by Bubnoff; 06-17-2010 at 03:09 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Red Hat

Use variable that needs "" in remote ssh command.

I want to use the below but since the date has a space it doesn't grep exactly what's needed. I need to keep the quotes around the variable when it passes it. I need the quotes around $DATE2 just to recognize the variable. Thanks in advance for any help given. D=`date +%d` DN=`echo -n $D |... (3 Replies)
Discussion started by: toor13
3 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. 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

5. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

6. Shell Programming and Scripting

The "read" command misinterprets file names containing spaces

The "read" command, which is built into bash, takes words from the standard input. However, "read" is not good at taking file names if the file names contain spaces. I would like my bash script to ask the user to enter file names, which may contain spaces. Can you think about any technique for... (14 Replies)
Discussion started by: LessNux
14 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

9. UNIX for Advanced & Expert Users

Running command "md5" on remote host not working.

My question is very strange. I can run ls command on remote host using ssh successfully. but when i try to run /sbin/md5 command on remote host. it doesnt run and get back to me on command prompt. md5 command is exist on remote host. This is what i tried which ran successfully. Query -... (1 Reply)
Discussion started by: ynilesh
1 Replies

10. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies
Login or Register to Ask a Question