Get the log and return the right value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the log and return the right value
# 8  
Old 12-19-2012
Quote:
Originally Posted by yanglei_fage
I will try it, but set -v seems not make it.it's strange
It won't display the shell prompt. But it will display the commands and results. So if you want shell prompt as well, then using script is the best option.
Quote:
Originally Posted by yanglei_fage
seems "script" can't be used in the function in my script
Here is how you can use script command:-
Code:
script collect_log

This will log all results into the file collect_log. This will open a sub-shell and records all information through this session. The script ends when the forked shell exits. I hope this helps.
# 9  
Old 12-19-2012
Quote:
Originally Posted by bipinajith
It won't display the shell prompt. But it will display the commands and results. So if you want shell prompt as well, then using script is the best option.
Here is how you can use script command:-
Code:
script collect_log

This will log all results into the file collect_log. This will open a sub-shell and records all information through this session. The script ends when the forked shell exits. I hope this helps.

Oh, but it seems useless for me, I just want to make the function in my script.

Code:
#!/bin/bash
LOG=mylog
define a fuction collect_log ---------> here
cd /root/;ls |grep .sh
collect_log 
lspci |grep 0000
collect_log

# 10  
Old 12-19-2012
script is the right approach, but if you don't want to use it, then run bash in interactive mode with option "-i" and read all the commands through stdin.
Code:
echo 'cd /root/;ls |grep .sh
lspci |grep 0000' | bash -i > mylog 2>&1
# or
bash -i < file-with-commands > mylog 2>&1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

2. Shell Programming and Scripting

how should I get the return value

ls xx > yy.log echo $? can get the return value of "ls xx" but if I use ls xx |tee -a yy.log I can't get the return value of "ls xx", and I get the return value of the whole cmd "ls xx |tee -a yy.log", it is always "0" my question is how could I get the return value of "ls xx"... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

3. Shell Programming and Scripting

Writing a UNIX script from LOG to provide return code.

Folks - Firstly, I do apologize that my first post here is a question. I am quite familiar with UNIX since our application is running on it. We are trying to automate a few things on our end and I am challenged with a task in hand that requires UNIX scripting. I am totally a newbie in UNIX... (4 Replies)
Discussion started by: sk72
4 Replies

4. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

5. Programming

cp and rm return non zero value

rm and cp return non zero values sometimes. sprintf(tmp, "rm -rf %s/* 2>/dev/null\n", dest); rc = system( tmp ); rc = 1 and errno =0 sprintf(tmp, "cp -r %s/* %s 2>/dev/null", source, dest); rc = system( tmp ); rc = -1 and errno = 2. The files exist and the paths are correct. I can... (7 Replies)
Discussion started by: latitude
7 Replies

6. Solaris

/var/cron/log Return Codes

I want to know if there is any documentation or any type of information that can give a list of all of the return codes that can be seen in the /var/cron/log. I have seen a couple in my log file. Example: rc=1 and rc=64. (2 Replies)
Discussion started by: sjames
2 Replies

7. UNIX for Dummies Questions & Answers

Return Value

How do I find out the return value of a shell script or program in Unix? Is there a command to find that out?? (1 Reply)
Discussion started by: carl_vieyra
1 Replies

8. Shell Programming and Scripting

Get the return log file

I have an execution in my shell script when run return a xxx.log file how wil i be able to get the name of the file and read it then test the string written in the file by the programs... Anyone can help me please... Am new to shell programming...... Lutchumaya (1 Reply)
Discussion started by: Lutchumaya
1 Replies

9. Shell Programming and Scripting

the return value $?

Could someone tell me that's the return value $? 15 mean? Where can i find out more? Many thanks (3 Replies)
Discussion started by: gusla
3 Replies

10. Shell Programming and Scripting

Return value

Hallo I want write a sh script but I have some troubles! How can I write the Return value to a variable? I need an egrep command with the option -c, how many times it give the pattern. This return value shold be written in a variable. Could you help me? (1 Reply)
Discussion started by: raphael.schwend
1 Replies
Login or Register to Ask a Question