As part of an expect script, I have to convert a strange user ID to a conventional UNIX ID. To do this, I read the contents of a file and do a little awk magic. Here's that bit of the expect script:
Let's say that the output of the awk command is "bob". Once executed, afaik, the above causes the contents of expect_out(buffer) to be exactly:
I can assign *all* of the buffer to a variable:
But all I want to assign to the variable is the last line before the prompt -- "bob". How do I do that? If it matters, I'm a little unclear about whether the prompt is actually in expect_out(buffer) or not. I might be asking how to save only the last line, or perhaps only the second-to-last. Please pardon my ignorance-- this really is my first attempt at an expect script, and the assignment of portions of output to a variable seems potentially useful.
---------- Post updated 02-04-10 at 11:24 AM ---------- Previous update was 02-03-10 at 07:11 PM ----------
(Moved thread to "Shell Programming..." from "...for Dummies")
---------- Post updated at 01:23 PM ---------- Previous update was at 11:24 AM ----------
Ah, ok... I think we have a winner. I learned about lindex and split, and so I added:
That does the trick... now $servername can be called as needed later in the script. It's a little offensive to do it in two steps like that... I'll look into combining when I have time to brush up on TCL/Expect syntax.
Sorry for the probably strangely worded title but I don't really know how else to put it.
Background context: Post processing LAMMPS simulation data.
tl;dr: I'm making two spheres collide, every defined timestep the simulation outputs a bunch of data including total energy of the particles,... (10 Replies)
Hi,
I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script):
#!/usr/bin/expect
set timeout 1... (3 Replies)
Unable to get the value to a variable.
set -x
cd $HOME
echo "Enter the server name"
read a
echo $a
i=4
j=1
k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j`
echo $k
When I do the same in command line it works, however the same does not work when I provide that in the... (1 Reply)
hi,
i'm creating a little menu for some users.
i'm running the command:
du -a /apps | sort -n -r | head -n 10 | nl
i then get the top 10 files by size in the /apps directory
the output is like this:
1 101415752 /apps
2 89188064 /apps/userA
3 74521335 ... (1 Reply)
Hi All,
I have been using a program on windows called AutoKey.
My environment at work is Linux and I have been experimenting with expect. Very powerful. I can move my AutoKey scripts to Linux using Expect once I am educated on how to read from a file using Expect.
My application would be... (1 Reply)
my script is some thing like this
i11="{1,2,3,4,5,6,7,8,9,10,11,}"
echo "enter value"
read value ..............suppose i11
x="$value"
echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,}
but its showing "i11" only.
plz help me out to get desired... (10 Replies)
Friends,
I have a file output.txt with values as below:
092307135717
061910135717
I want to know how to read this file and then assign each value to a variable.
say like
var1=092307135717
var2=061910135717
So that I can use this VAR1 and Var2 in the shell script for further processing.... (3 Replies)
Hi folks.
I have this variable called FirstIN that contains something like this: 001,002,003,004...
I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces)
I thought about using sed but i am not... (17 Replies)
Hello
I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable:
FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}`
When the command... (6 Replies)