I think you missed a level of quotes escaping. At this high level of escaping, it is best to simply make a little script for every stage where otherwise quotes would be required.
Otherwise, you could try this modified version (but mind you, I don't encourage this coding style!)
function _remoteInstallation(){
local retval=1
local debToInstall=$(basename "$1")
local remoteMachine="$2"
spawned=$(expect -d -c "
set timeout 1800
spawn \"/usr/bin/ssh -t borrajax@$remoteMachine /usr/bin/sudo /usr/bin/dpkg -i /home/borrajax/Documents/$debToInstall\"
expect {
\"Are you sure you want to continue connecting\" { send \"yes\r\"; exp_continue }
\"password\" { send \"myPassword\r\"; exp_continue }
\"[sudo] password\" { send \"myPassword\r\"; exp_continue }
default { exit 1 }
}
" )
retval=$?
return $retval
}
1) I'm not sure if the subshell (or backgrounding) is useful here:
sudo sh -c '( tail -n1 -f /path/to/nameOfLog.log & ) | grep -q "Started .*Application"'
shouldn't a simple pipe do?
sudo sh -c 'tail -n1 -f /path/to/nameOfLog.log | grep -q "Started .*Application"'
2) Your "try 1":
sudo timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)
expands the input redirection <()
on the command line that runs the sudo
, not inside sudo
. The filehandle it opens isn't passed through sudo
to grep
, so grep
can't open the /dev/fd/63
pseudo-file.
Same thing about backgrounding the tail
here, it shouldn't be necessary.
3) And, as phk commented, your "try 2":
sudo sh -c 'timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)'
...explicitly runs sh
, and not bash
or any other more featureful shell. Plain standard sh
doesn't support <()
, and neither does dash
which is used as sh
on Debian and Ubuntu.
When you run su
instead, it runs root
's login shell, which is likely to be bash
on Ubuntu. But using both sudo
and su
is redundant, they're both made to elevate privileges, and after sudo
you're already running elevated privilege, so no need for su
. Instead, if you want to run a shell inside sudo
, just say explicitly which one:
sudo bash -c 'timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)'
Best Answer
You need to remove the double-quotes. It is trying to run a command called "ulimit -Hn" as a single command, spaces and all.
-s
needs to be the lastsudo
option on thesudo
command line, and all following arguments are passed to$SHELL -c
to execute.I guess the way
-s
is processed has changed, as the current way allows you to pass arguments with spaces to$SHELL
by escaping them on the command line:The old method of argument handling would split that
'/tmp/foo bar'
argument into two, breaking the command.