0

For development purposes, I use a script that automatically connects to a host to do stuff. I always need to hit the [ENTER] key so that it connects and reconnects (upon reboot of the host). I would like to modify it so, that no user interaction is required. How can do this?

I don't need lessons on using the root account to login, it's all under control - please, just believe me. (embedded platform, no user I/O. Plus root account will be disabled before going live) There also is no password assigned to it, either! What I have so far:

#!/bin/bash

if [ "$3" == "auto" ] ; then
    arg= 'sleep 1';
    ssharg='-v -o ConnectTimeout=1 -o ConnectionAttempts=1 -o StrictHostKeyChecking=no -p 2222';
else
    arg= 'read';
    ssharg='-o StrictHostKeyChecking=no -p 2222';
fi
#$dbg should be executed when connecting with parameter lx
dbg=`scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P 2222 ~/local/script root@$1:/path/to/script`;`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 root@$1 -n /path/to/script`;

if [ $2 == "lx" ] ; then
    $dbg;
    ssh -o StrictHostKeyChecking=no -p 2222 root@$1; echo "Reconnect?";sleep 1; while $arg; < /dev/tty; do $dbg; ssh -o StrictHostKeyChecking=no -p 2222 root@$1; echo "Reconnect?"; done

...
More similar elifs checking for other parameters (in $2) without requirement to tun $dbg beforehand
...

Which works fine only that I have to press [ENTER] after launching the script and to reconnect.

  • Can you give us a clue? Where in the script does it ask you to press <kbd>Enter</kbd>? – ctrl-alt-delor Jul 17 at 0:03
2

This line

    arg= 'read';

Because there's a space after =, this line temporarily sets the arg variable to the empty string, then executes the read command which reads data from stdin -- since you don't redirect any data into read's stdin, the user must enter a line of text on the terminal. read stores the user's entry into the $REPLY variable. Following this, the arg variable will be unset.

To assign the 'read' string to the arg variable, you must not put whitespace around =


This part looks suspect: while $arg; < /dev/tty; do -- why is there a semicolon after $arg?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.