Script that will output everything to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that will output everything to file
# 1  
Old 10-03-2008
Computer Script that will output everything to file

Hello,

I am kinda new to Unix scripting, haven't really dabble very deep, but I am trying to at the moment.

Currently I am attempting to create a install script for my software. However what i would like to do is EVERYTHING that is outputted to screen (Including user input), is sent to a log file of my chosing.

E.g: variable set for Xfile name to X directory.

I know this is probably quite trivial but i would love it if you could give me some help if at all possible.

I am writing this sh script on on Linux (CentOS) .

Also, if you have any good links to some good Shell scripts commands or cheat sheets that would be awesome!.

Many thanks again.
# 2  
Old 10-03-2008
type

echo put this in a file called file.txt > file.txt

using the ">" you just output to a file.txt


cat file.txt


want to add something else use ">>" to put more on the end

echo i want to add more stuff to my file.txt >> file.txt

cat file.txt
put this in a file called file.txt
i want to add more stuff to my file.txt

IS THAT WHAT YOU WANTED?
# 3  
Old 10-04-2008
you can also use tee command
# 4  
Old 10-04-2008
I understand how to use "> log_file" but that would only work for one command, and i would have to put that everywhere in the script!

I want everything that my script outputs to the screen placed in a log file, including user input.

Is there no an easier way of doing this?

Such as

Start Script --

Create logfile/Start recording --

Commands issued by the script
Commands issued by the script
Commands issued by the script
Commands issued by the script
User input
Commands issued by the script
Commands issued by the script
Commands issued by the script

Stop recording

End of script.
# 5  
Old 10-04-2008
if you are using linux ( redhat or centos in particular, as I have to explored on other Nix'es ) are you looking for : script command



[root@server ~]# script
Script started, file is typescript
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]# cat typescript
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]# vi 123
[root@server ~]# vi 12345
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]#
[root@server ~]# exit
Script done, file is typescript
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 1375 Oct 4 17:21 typescript
[root@server ~]# cat typescript
Script started on Sat 04 Oct 2008 05:20:08 PM IST
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]# cat typescript
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]# vi 123
[root@server ~]# vi 12345
[root@server ~]# ls -l typescript
-rw-r--r-- 1 root root 0 Oct 4 17:20 typescript
[root@server ~]#
[root@server ~]# exit

Script done on Sat 04 Oct 2008 05:21:02 PM IST
[root@server ~]#
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

3. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

4. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

5. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

6. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

8. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

9. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

10. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies
Login or Register to Ask a Question