I have a script that must perform a 'sudo' operation on each of a number of hosts. I'm trying to get expect working so I only have to enter it once, and have run into a couple of issues.
First, several examples suggest to use:
However, as soon as I enter the second '<', all of the quoting gets screwed up, and my script will terminate with an unexpected end of file. This is really strange, as I use the same mechanism with cat to write out files in other scripts.
Other examples suggest:
Doing it this way (and adding -d to expect), I get errors about no tty and a repeat of my password with an 'n' appended to the end, so it isn't sending a newline (I've tried '\r' as well), but instead appears to be escaping the 'n'
Since most of the examples I'm finding are from Linux, I expect (ha, ha, pun not intended!) that they're using a GNU expect, and I'm using a BSD expect. I am reading through the man page, but the word "spawn" appears so many times, it could be quite a while before I stumble across the correct instance.
Here's a result that seems to be closest to working:
That's with leaving the '\n' outside of the quotes, as in
It seems to be mostly working, except skipping the '-t' option to ssh
That isn't in the man page, but I tried it anyway. No difference
---------- Post updated 02-27-13 at 01:30 PM ---------- Previous update was 02-26-13 at 01:37 PM ----------
I found this link which gave me some useful info... removing preceding indentation from my expect lines got me going! However, now, lines where I echo text or variables interspersed with '/t' no longer contain tabs, but literal '/t' strings!
I usually write expect using autoexpect. It is very fussy! Perhaps use quoted real tabs?
The lines with the tabs are not in the expect portion. I did replace them with real tabs, and that works, but... jeez Louise! That isn't very maintainable!
Here's what I'm trying to get. In my non-expect version, I use:
That works... it returns a four-digit build number, which is exactly what I want. But that scrip prompts me for my sudo password once for each host it hits, which can be a pain. So in my expect version, I have:
That is very literally the only difference between the two versions of my script. I am befuddled as to why that screws up tabs in other lines. Also, this way, my HBSSVER= line no longer works... it hangs at my cut statements. IIRC, that's why I was using 'sudo -v', so that the password could be entered and cached on the remote host, and the second line could just run without prompting.
And, yes, I know I technically could change permissions on the /etc/cma.conf file to no longer need sudo That isn't an option, either. If you've never dealt with HBSS, consider yourself lucky and just trust me
Have you considered running these things on the root cron or a root service so they can be created with read permission to your id or your user's ids.
I guess tabs are meta to expect, and if they lose their quoting or escaping, they are just white space!
You should be able to send one block of code through, or on the command line of, one ssh session and get all your answers from the output on stdout and stderr.
BTW, the first actually becomes bash -c '...' on the remote side for non-trivial '...'
I am not a big fan of the here document '<<' ; there are places it is great, like plain text lists, but for shell it has less control than "echo '...' |ssh bash", where exactly what you say goes down the pipe unprocessed to a remote shell. If you need something on this side that ' blocks, slip out to ", do it , then out of " and back to '. If you want that same control over on the remote shell, ' becomes '"'"' (single-double-single-double-single). No surprises, no extra quote stripping. I try to stay away from '\' for similar reasons. They disappear with little warning.
im very happy to back for this forum
I have servers with alias of double dns extentions:
sample:
servera.test.com
servera.test1.com
serverb.test.com
serverb.test1.com
I need to login to that severs and executing the set of commands
if test.com failed then try to login via... (0 Replies)
Hi All,
I have written a script to automate scp of files. Most of the times it works fine except few cases. I want your help and suggestions to fix these failures.
I have used expect & shell to do the automated scp. Below is code
$ cat scp.ksh
#!/bin/ksh
inputfile=$1
fdest_sid=$2... (8 Replies)
I have a script that writes another script with
cat >/usr/local/bin/myscript.sh <<EOF
#!/bin/sh
VAR=`run a command here`
EOF
Problem is, after this is run, I get:
$ cat /usr/local/bin/myscript.sh
#!/bin/sh
VAR=result of command
How do I stop that from happening with Macs... (2 Replies)
Can you explain what this line of script is doing.
What I have understood is :
-- variable C is the name of a software which is either not installed, so it must be installed or allready installed and then should be update if newer version found
-- branch B="$B $C" is to install the software
--... (4 Replies)
Hi guys, I'm new here and new to shell scripting so don't be hard on me
I'm trying to create a bash script to restart a process by name in Mac OSX.
I have no problem killing the application, the problem comes when launching it again.
I managed to store the path in a variable lets say
... (8 Replies)
Hi, I'm writing a shell script that calls a few commands that prompt the user for two simple yes/no questions. if the answers are consistent (the first is a yes, the second is a no), what would my expect script look like? Google is only giving me answers for scripts where I telnet or ssh. right now... (3 Replies)
I am having an issue where I am do an SSH to about 30 servers one at a time however my script is getting hung up sometimes on the SSH.
I thought the & at the end as seen below would fire it and move on but that does not seem to be working.
#!/bin/s
for remsys in trumpetsnail angel delphin... (3 Replies)
Hi there,
Hope this isn't too complex of a script to try to make but this is what I'm trying to do.
Create a new group and add local users that aren't admin to the group.
So let's say the new group is 'cats' and 'dog' is the only admin on the machine. Let's say most machines only have one... (4 Replies)
i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine.
then last week i wrote capture.sh and it... (2 Replies)
Hi,
I have installed bash 3.2 via darwin ports, however when I try and change the shell i.e. chsh -s /opt/local/bin/bash is says its a non-standard shell? but if i run ./bash i get a new bash prompt with version 3.2?
Thanks (3 Replies)