bash - how to get the command and output logged in shell? -


we need log command , output. example if run following command. need log text file.

cat script.sh find / -name sshd_config -print /etc/ssh/sshd_config 

cat log.out --should below

<server_name>$ find / -name sshd_config -print /etc/ssh/sshd_config 

if use set-x in script, can log command gives information. there alternate way use in scripts?

i curious , followed up: here's expect script makes shell script interactive:

#!/usr/bin/env expect  set script [lindex $argv 0] if { ! [file readable $script]} {     error "cannot read $script" }  set fid [open $script r] set lines [split [read -nonewline $fid] \n] close $fid  set shebang [lindex $lines 0] if {[string match {#!*} $shebang]} {     spawn -noecho {*}[string range $shebang 2 end] } else {     spawn -noecho $env(shell) }  foreach line $lines {      # skip blank lines     if {[string trim $line] eq ""} continue     # skip comments     if {[string match {#*} [string trim $line]]} continue     send -- "$line\r"  }  # send ctrl-d end shell session send -- \x04 expect eof 

save interactivize, then:

$ cat test.sh date getent passwd $user echo hello world $ interactivize test.sh date getent passwd $user echo hello world [myprompt]$ date thu apr  9 18:29:31 edt 2015 [myprompt]$ getent passwd $user jackman:x:1001:1001:glenn jackman:/home/jackman:/usr/local/bin/fish [myprompt]$ echo hello world hello world [myprompt]$ exit exit 

Popular posts from this blog