What's wrong with script?
shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
Along the same lines as Gromit suggests, try this (I lay no claim to the name 'dupit') Here's a baby script:
output=script_out_file
rm -f $output
touch $output
dupit() {
echo "$@" >> $output
$@ >> $output
}
dupit echo "HELLO"
dupit ls -lrt
dupit echo "GBYE"
dupit sleep 2
Invoke the script as bash the_script; cat script_out_file It will appear to run for too long. That's ok, because we told it to sleep for 2 seconds. Minor syntax changes for shells other than bash.
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
script is working as it is meant to. What script does is start another shell, and record the putpot from that shell in the logfile. When you've finished exit the shell and script will close the logfile and exit, from there your shell script will continue. What is it that you are trying to achieve?
shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
Script works as specified, but it doesn't do what OP needs: both the command and the output.
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
It does, both command and output. I suspect that the OP is running script in a shell script and expecting ti to log everything that happens after it start, which of course it won't.
shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
Both commandand output are available, however, until the OP states exactly what he is trying to achieve there's not much else we can do.
user_id@directory googlecl-0.9.12]$ script
Script started, file is typescript
[user_id@directory googlecl-0.9.12]$ ls -l
total 64
-rw-r--r-- 1 user_id user_id 741 Jun 16 2010 INSTALL.txt
-rw-r--r-- 1 user_id user_id 821 Jan 21 23:49 PKG-INFO
-rw-r--r-- 1 user_id user_id 5198 Dec 17 00:50 README.config
-rw-r--r-- 1 user_id user_id 5241 Jan 18 01:14 README.new-usage
-rw-r--r-- 1 user_id user_id 14562 Nov 15 13:31 README.txt
drwxr-xr-x 4 root root 4096 Jan 23 14:43 build
-rw-r--r-- 1 user_id user_id 5463 Jan 18 01:15 changelog
drwxr-xr-x 2 user_id user_id 4096 Jan 21 23:49 man
-rw-r--r-- 1 user_id user_id 3219 Jan 18 01:17 setup.py
drwxr-xr-x 3 user_id user_id 4096 Jan 21 23:49 src
-rw-r--r-- 1 user_id user_id 0 Feb 16 01:42 typescript
[user_id@directory googlecl-0.9.12]$ exit
exit
Script done, file is typescript
[user_id@directory googlecl-0.9.12]$ cat -v typescript
Script started on Wed Feb 16 01:42:06 2011
^[]0;user_id@directory:~/googlecl-0.9.12^G^[[?1034h[user_id@directory googlecl-0.9.12]$ ls -l^M
total 64^M
-rw-r--r-- 1 user_id user_id 741 Jun 16 2010 INSTALL.txt^M
-rw-r--r-- 1 user_id user_id 821 Jan 21 23:49 PKG-INFO^M
-rw-r--r-- 1 user_id user_id 5198 Dec 17 00:50 README.config^M
-rw-r--r-- 1 user_id user_id 5241 Jan 18 01:14 README.new-usage^M
-rw-r--r-- 1 user_id user_id 14562 Nov 15 13:31 README.txt^M
drwxr-xr-x 4 root root 4096 Jan 23 14:43 ^[[0m^[[01;34mbuild^[[0m^M
-rw-r--r-- 1 user_id user_id 5463 Jan 18 01:15 changelog^M
drwxr-xr-x 2 user_id user_id 4096 Jan 21 23:49 ^[[01;34mman^[[0m^M
-rw-r--r-- 1 user_id user_id 3219 Jan 18 01:17 setup.py^M
drwxr-xr-x 3 user_id user_id 4096 Jan 21 23:49 ^[[01;34msrc^[[0m^M
-rw-r--r-- 1 user_id user_id 0 Feb 16 01:42 typescript^M
^[]0;user_id@directory:~/googlecl-0.9.12^G[user_id@directory googlecl-0.9.12]$ cat^H ^H^H ^H^H ^Hexit^M
exit^M
Script done on Wed Feb 16 01:42:14 2011
[user_id@directory googlecl-0.9.12]$
shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6
Both command and output are available from script, as shown, but until the OP lets us know what he is trying to achieve there's not much more that we can do. If he is try to pick this up from a script rather than keyboard input he'd probably do better if he was to try
set -v
and redirect the output.
user_id@server googlecl-0.9.12]$ script
Script started, file is typescript
[user_id@server googlecl-0.9.12]$ ls -l
total 64
-rw-r--r-- 1 user_id user_id 741 Jun 16 2010 INSTALL.txt
-rw-r--r-- 1 user_id user_id 821 Jan 21 23:49 PKG-INFO
-rw-r--r-- 1 user_id user_id 5198 Dec 17 00:50 README.config
-rw-r--r-- 1 user_id user_id 5241 Jan 18 01:14 README.new-usage
-rw-r--r-- 1 user_id user_id 14562 Nov 15 13:31 README.txt
drwxr-xr-x 4 root root 4096 Jan 23 14:43 build
-rw-r--r-- 1 user_id user_id 5463 Jan 18 01:15 changelog
drwxr-xr-x 2 user_id user_id 4096 Jan 21 23:49 man
-rw-r--r-- 1 user_id user_id 3219 Jan 18 01:17 setup.py
drwxr-xr-x 3 user_id user_id 4096 Jan 21 23:49 src
-rw-r--r-- 1 user_id user_id 0 Feb 16 01:42 typescript
[user_id@server googlecl-0.9.12]$ exit
exit
Script done, file is typescript
[user_id@server googlecl-0.9.12]$ cat -v typescript
Script started on Wed Feb 16 01:42:06 2011
^[]0;user_id@server:~/googlecl-0.9.12^G^[[?1034h[user_id@server googlecl-0.9.12]$ ls -l^M
total 64^M
-rw-r--r-- 1 user_id user_id 741 Jun 16 2010 INSTALL.txt^M
-rw-r--r-- 1 user_id user_id 821 Jan 21 23:49 PKG-INFO^M
-rw-r--r-- 1 user_id user_id 5198 Dec 17 00:50 README.config^M
-rw-r--r-- 1 user_id user_id 5241 Jan 18 01:14 README.new-usage^M
-rw-r--r-- 1 user_id user_id 14562 Nov 15 13:31 README.txt^M
drwxr-xr-x 4 root root 4096 Jan 23 14:43 ^[[0m^[[01;34mbuild^[[0m^M
-rw-r--r-- 1 user_id user_id 5463 Jan 18 01:15 changelog^M
drwxr-xr-x 2 user_id user_id 4096 Jan 21 23:49 ^[[01;34mman^[[0m^M
-rw-r--r-- 1 user_id user_id 3219 Jan 18 01:17 setup.py^M
drwxr-xr-x 3 user_id user_id 4096 Jan 21 23:49 ^[[01;34msrc^[[0m^M
-rw-r--r-- 1 user_id user_id 0 Feb 16 01:42 typescript^M
^[]0;user_id@server:~/googlecl-0.9.12^G[user_id@server googlecl-0.9.12]$ cat^H ^H^H ^H^H ^Hexit^M
exit^M
Script done on Wed Feb 16 01:42:14 2011
[user_id@server googlecl-0.9.12]$
shibblez
Junior Poster in Training
72 posts since Oct 2010
Reputation Points: 15
Solved Threads: 6