Sponsored Content
Top Forums Shell Programming and Scripting Expect script to collect logs in expert mode Post 303003237 by shunya on Sunday 10th of September 2017 09:35:08 PM
Old 09-10-2017
RedHat Expect script to collect logs in expert mode

I am trying to collect logs from a system in expert mode. Where I login to system and then change mode to expert mode and issue command to collect the log. I have a script which works but It waits for 30 mins even though log collection is complete before that. I have two issues with existing script.

1. Since log collection takes really long time (sometimes about 30 minutes). Expect script does not wait for the prompt and exits at timeout value. So I don't get complete O/P. Hence, I added timeout value of 1800 secs. But this one forces script to wait for 30 mins. I would like to exit as soon as I am back on prompt. I tried using expect exact but need some help on this.

2. How can I capture the current prompt itself as a variable and ask Expect to wait until it gets the prompt. or Make a prompt based on Username variable and hostname lie - USERNAME@SYSNAME##.

Here is my current code.
Code:
#!/usr/bin/expect -f
set timeout 5
set hostname [lindex $argv 0]
set username "admin"
set password "password"
set prompt "(>|#|\\\$) $"


spawn ssh $username@$hostname
expect {
    ".*key fingerprint" {send "yes\r"; exp_continue}
    "assword:" {send "$password\r"}
}

expect -re {\$prompt}

send "show product id\r"

expect -re "\nProduct ID: (.*)$prompt"
set PRDID $expect_out(1,string)

#send "hostname\r"
#expect -re "\n (.*)$prompt"
#set HNAME $expect_out(1,string)



expect -re $prompt
send "expert mode\r"
expect -re "assword:" {send "$PRDID\r"}
#send "$PRDID\r"
expect -re $prompt
#set output $expect_out(buffer);

send "show detailed logs\r"
set timeout 1800  ### To wait for 30 mins
## expect -re $prompt
expect -exact "(.*)## $"   ### I tried using expect exact. But it seems something wrong here.
###  expect -exact "\nSA@$HNAME##$"
send -- "\r"
send "exit\r"
#puts [open w] $expect_out(buffer);
expect eof
[root@se scripts]#

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

2. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

3. Shell Programming and Scripting

script to collect all db information

hi all I am looking for shell script ,by which i need to gather all the DB information in Sybase server . Thanks in advance :) (3 Replies)
Discussion started by: mvsramarao
3 Replies

4. Shell Programming and Scripting

Expect command use for interactive mode of scripting

Hi All, I am writing a script(Auto_Installation.sh) which is calling one another script (./update_manager /spare/install/HO7/PME_Response_file.txt) Now the issue is result of (./update_manager /spare/install/HO7/PME_Response_file.txt) script is ##########################################... (6 Replies)
Discussion started by: Dhruvak
6 Replies

5. Red Hat

collect red hat linux error logs

Hi, I have two questions,first of all is where can I collect more error logs(the log under /var/log/messages), also give the corresponding explain is grateful.The second one is the log under various versions(such as red hat,suse,etc) is the same or not. Thanks for answers. (1 Reply)
Discussion started by: zhaoyy
1 Replies

6. Shell Programming and Scripting

How to collect the logs with in two time stamp ?

Hi Gurus I need to collect the logs between two time stamp... The log files 12 hours format (ex- Nov 14, 2013 12:10:16 AM UTC) I tried the below commands but no luck. awk '$0 >= "Nov 14, 2013 9:40:01" && $0 <= "Nov 14, 2013 9:55:01"' file sed -n '/Nov 14, 2013 7:58:00 PM UTC/,/Nov 14, 2013... (5 Replies)
Discussion started by: zenkarthi
5 Replies

7. Shell Programming and Scripting

Expect doesn't output the logs

(qemu) migrate -d tcp:192.168.122.1:4444 (qemu) info migrate capabilities: xbzrle: off Migration status: completed total time: 4425 milliseconds downtime: 3 milliseconds transferred ram: 130338 kbytes remaining ram: 0 kbytes total ram: 1057152 kbytes duplicate: 232613 pages normal:... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

8. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

9. UNIX for Beginners Questions & Answers

How to set file transfer in binary mode in SFTP using Expect?

The below is my script. /usr/bin/expect<<EOD spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST expect "sftp>" expect "password:" set timout 15 send "$password\r" expect "sftp>" send "lcd $remotedir\r" expect "sftp>" ... (1 Reply)
Discussion started by: Anilsaggu9
1 Replies
csdiagnose(1)						    BSD General Commands Manual 					     csdiagnose(1)

NAME
csdiagnose -- collect information needed to diagnose CoreStorage volumes SYNOPSIS
csdiagnose [-f path] [-h] [-v] [dev ...] DESCRIPTION
csdiagnose collects information to help Apple investigate issues related to CoreStorage (File Vault 2, Fusion Drive, File Vault Everywhere, etc). This tool invokes sudo, so you will be asked to authenticate. This script requires csgather(1) to be installed in the PATH. If dev is not given, all disks in the system will be inspected. This is the recommended method of invoking csdiagnose. Advanced users can provide a list of dev in the form of disk1 or disk1s2. Only information of the given dev is collected. To fully collect information of a CoreStorage volume, the CoreStorage Physical Volume (i.e., the Apple_CoreStorage partition), the Apple_Boot partition after the physical volume, and the Logical Volume published by CoreStorage (which can be found out using the "diskutil cs list" command) should all be provided on the command line. The following information is collected: 1. OS version. 2. system logs, kernel logs, install logs, filesystem logs, and other useful information for CoreStorage debugging from /var/log. 3. output of "diskutil list". 4. output of "diskutil cs list". 5. output of "mount -t hfs". 6. "csgather -G" of every Apple_CoreStorage partition, which includes the CoreStorage metadata. If a list of dev is provided, only information on the partitions included in the list will be collected. 7. EncryptedRoot.plist of every Apple_Boot partition. If a list of dev is provided, only information on the partitions included in the list will be collected. 8. timestamps of the files relevant to kextcache/kextd. The following user information is contained in the collected file: 1. Number and types of disks attached to the system. 2. The volume names, UUIDs, and size of each partition. 3. Encrypted versions of the volume key(s) that unlock the encrypted disk(s) attached to the system. Refer to csgather(1) for what information could leak from the volume key(s). 4. User names, pictures, and password hints for the users. No other user information (such as directory structures, file names, file content, etc) is collected. The following options are available: -h Show this help information. -f path Specify an output path which will hold the file generated by this script. By default this will be the user's Desktop folder. The given path must already exist. -v Verbose mode, which prints every command it invokes. SEE ALSO
csgather(1), sysdiagnose(1) HISTORY
The csdiagnose utility first appeared along with CoreStorage in OS X 10.10.0. OS X
May 31, 2019 OS X
All times are GMT -4. The time now is 02:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy