I want to save the unix terminal command and out to store in a file for a session. Because some time unix command output are so large, so we con not get back by scrolling up in terminal.
Why not pipe the output to tee ? That will record in a file and dump to the console so you can see in real time what's going on.
$ mycommand | tee filename.log
Note that the above will only record stdout. If you need to record stderr too, then redirect accordingly:
$ mycommand 2>&1 | tee filename.log
(assuming you're using sh or a compatible shell - most likely)
Use the script filename command.
Related
In my Linux environment, I am using a installed command that is of this format.
command1 -u <username> -p <password-file> ...
where in this password-file, it keeps a password value of the text format, such as "abc".
When running this command, I feel it is very inconvenient to every time create a file to hold this password value! So is there a way I can feed this "abc" value directly on this command line ???
Thanks,
Chun
If you are using bash (and if you are running in Linux, chances are good you are, or can) you can do:
command -u username -p <(echo abc)
which is equivalent to passing the name of a file with contents "abc\n".
I've got a script on my computer named test.py. What I've been doing so far to run the program is type python test.py into the terminal.
Is there a command on Unix operating systems that doesn't require the user to specify the program he/she uses to run the script but that will instead run the script using whichever program the shebang line is pointing to?
For example, I'm looking for a command that would let me type some_command test.txtinto the terminal, and if the first line of test.txt is #!/usr/bin/python, the script would be interpreted as a python script, but if the first line is #!/path/to/javascript/interpreter, the the script would be interpreted as javascript.
This is the default behavior of the terminal (or just executing a file in general) all you have to do is make the script executable with
chmod u+x test.txt
Then (assuming text.txt is in your current directory) every time you type
./text.txt
It will look at the sh-bang line and use the program there to run text.txt.
If you really want to duplicate built-in functionality, try this.
#!/bin/sh
x=$1
shift
p=$(sed -n 's/^#!//p;q' "$x" | grep .) && exec $p "$#"
exec "$x" "$#"
echo "$0: $x: No can do" >&2
Maybe call it start to remind you of the similarly useful Windows command.
I am using Putty plink command line utility to run a few scripts on my UNIX server. I use the -m option as:
plink -ssh -pw xxx myserver –m file.txt
The file file.txt contains a list of commands that are to be executed and is generated dynamically using some application program. Some of the commands in file.txt can run for hours, which will make the user wait for a long time. Moreover, I am interested in execution of the first line of each of the scripts.
So I want to make sure that a control+c command is sent just after the script is run so that complete script is not run. So instead of using the following in my file.txt:
script1
script2
script3
I want to use:
script1
control+C command
script2
control+C command
script3
control+C command
Can anyone help me in writing this control+c in my file.txt?
Thanks a lot
What is the difference between
cat dat | tee >(wc -l ) | some other command
and
cat dat | tee file | wc -l
in terms of what is happening under the hood?
I can understand the second one as tee is forking the stream into a file and also to a pipe. But I am confused with the first one.
The first notation is the process substitution of Bash 4.x (not in 3.x, or not all versions of 3.x).
As far as tee is concerned, it is given a file name (such as /dev/fd/64) to which it writes as well as to standard output; it is actually a file descriptor for the write end of a pipe. As far as wc is concerned, it reads its standard input (which is the read end of the pipe that is connected to /dev/fd/64 for tee), and writes its answer to the standard output of the shell invoking the pipeline (not the standard output of tee which goes down the pipeline).
Since >( is process substitiution of bash,
the first line says:
send the contents of file 'dat' into some other command
while process 'wc' is run with its input or output
connected to a pipe which also sends the content of 'dat'
check "Process Substitution" of bash manpage.
i'm running a script from ASP.NET/C# using SharpSsh. I realize when the script runs and i do a ps -ef grep from unix, i see the same script running twice, one in csh -c, and the other with ksh. The script has shebang ksh, so i'm not sure why a copy of csh is also running. Also if i run the same script directly from unix, only one copy runs with ksh. There's no other shell running from within the script.
Most Unix/Linux now have a command or option that will show process trees, with indented list like, look for -t or -T options to ps OR ptree OR ???
USER PID PPID START TT TIME CMD
daemon 1 1 11-03-06 ? 0 init
myusr 221568 1 11-03-07 tty10 1.00s \_ -ksh
myusr 350976 221568 07:52:11 tty10 0 | \_ ps -efT
I bet you'll see that the csh is the user login shell that includes your script as an argument ( you may have to use different options to ps to see the full command-line of the csh process) AND as a sub process you'll see ksh executing your script, and further sub-processes under ksh for any external commands that the script is calling.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, or give it a + (or -) as a useful answer.