EXPECT: Assign variable by reading a line of text from a file
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 as follows:
1. I have a list of MAC addresses in a text file format aa:bb:cc:dd:ee:ff. There will be one MAC address per line.
2. Expect script will need to read the first mac address in the file. Carry out some work with that MAC and then read the next MAC address and so on until the end of the file.
I have a script which works fine as follows, but the MAC is prompted by the user. This is the part which needs to be automated and the MAC address read from the line in the file so the MAC read from the file is the variable for.
I would appreciate some guidance on how to use expect to read the first line of a file, carry out the work needed with the MAC, and then loop back and get the next MAC until the end of the list.
This is Windows (sorry ) autokey script which reads from a file:
Expect is for interactive keyboard driven tools with no batch or script-friendly command line mode. If you make an expect script that works with one mac address, you could write a normal bash/ksh script to read the mac addresses, gen an expect script with that mac address embedded and run it. Expect is written in tk/tcl, as I recall, so you need skills in that arcane area to vary the script dynamically. I mostly write my expect scripts using autoexpect, or fake it using shell scripts reading the output file to determine progress. Are you going to windows autokey using telnet?
Hello,
I have a text file named "foreach.txt" which reads like ---
foreach cal ( 1 2 3 4 5 )
I am using a simple script which looks like ---
#!/bin/tcsh
foreach cal (1 2 3 4 5)
echo "$cal"
end
Is it possible to modify the script in such a way that instead of writing
foreach cal (1... (6 Replies)
Hello,
I am using below code for reading from a file and assigning the values to a variable , but it is loosing the value after the loop , please suggest to retain the value of the variable after the loop ,
while IFS=: read -r line
do
set $dsc=$line
echo 'printing line variable ' $line... (1 Reply)
Hi,
I am new to shell scripting. Need help with the below requirement.
I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table.
For E.g. file test.sql has below error:
ORA-01017:... (3 Replies)
I need some help. I would like to read in a text file.
Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01.
Is this possible? any help is appreciated. (2 Replies)
So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated.
Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Hi,
I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS>
I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it.
Using the following code prints the values... (12 Replies)
Hi,
I have a text file with multiple lines, each having data in the below format
<DOB>,<ADDRESS>
I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it.
Using the following code prints the... (1 Reply)
Hi,
I have a text file something like this:
10.10.10.1,
ldap,
cn=users,dc=example,dc=com
.....
...
and many more lines
...
...
now i want to read each individual line from the file and assign it to a variable
example:
the script should read 10.10.10.1 and assign it to a variable say... (3 Replies)
Hello All,
A part of my very basic perl code requires me to read a single value from a text file.
The file output is the following:
Reading image ... done
IMAGEREGION=0x0x0-256x162x256
VOXELDIMENSION=0.9375000000x1.2000000477x0.9375000000
VOXELNUMBER=10527001... (7 Replies)
Hi,
I am doing :
while read line
do
printf "%s\n" ${line}
done <datafile.txt
but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)