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
# 1  
Old 12-19-2012
Get the log and return the right value

Hi expert,

I'm a tester, I want to write a function with bash to collect log which the command I run. the log contains the "shell prompt--->
root@intel_5500_server:, and the last whole command in the shell ----> such as "cd /root/;ls |grep .sh"

to be clear it should be sommething like
Code:
root@intel_5500_server:~#cat my.log
root@intel_5500_server:~# cd /root/;ls |grep .sh
test.sh
test.sh~
vhost_libvirt.sh
vhost_libvirt.sh~
xx.sh

something like below I want a function like collect_log
Code:
#!/bin/bash
LOG=mylog
define a function named collect_log-------------->here
cd /root/;ls |grep .sh
collect_log 
lspci |grep 0000
collect_log

then I can get the log like
Code:
root@intel_5500_server:~#cat mylog
root@intel_5500_server:~# cd /root/;ls |grep .sh
test.sh
test.sh~
vhost_libvirt.sh
vhost_libvirt.sh~
xx.sh
root@intel_5500_server:~# lspci -nn |grep 05:00
05:00.0 Ethernet controller [0200]: Intel Corporation 82571EB Gigabit Ethernet Controller [8086:105e] (rev 06)
05:00.1 Ethernet controller [0200]: Intel Corporation 82571EB Gigabit Ethernet Controller [8086:105e] (rev 06)

1)I don't how to get "root@intel_5500_server:~#"
2)I don't know how to get "cd /root/;ls |grep .sh"

can some one help me, Is it possible to make it as a function

Last edited by yanglei_fage; 12-19-2012 at 11:35 AM..
# 2  
Old 12-19-2012
Code:
van12:/tmp/testsamples $ cat titi |grep "#"|awk -F'#' '{print $1}'
root@intel_5500_server:~
van12:/tmp/testsamples $ cat titi |grep "#"|awk -F'#' '{print $2}'
 cd /root/;ls |grep .sh
van12:/tmp/testsamples $

# 3  
Old 12-19-2012
Quote:
Originally Posted by vbe
Code:
van12:/tmp/testsamples $ cat titi |grep "#"|awk -F'#' '{print $1}'
root@intel_5500_server:~
van12:/tmp/testsamples $ cat titi |grep "#"|awk -F'#' '{print $2}'
 cd /root/;ls |grep .sh
van12:/tmp/testsamples $

No,you misunderstand what I say, I modified my question.


Moderator's Comments:
Mod Comment You modified 3 times your post AFTER I replied..., saying AFTER that the question was misunderstood shows lack of honesty from you

Last edited by vbe; 12-19-2012 at 11:25 AM..
# 4  
Old 12-19-2012
How about:-
Code:
{
 set -v
 cd /root/;ls |grep .sh 
 lspci |grep 0000
} > collect_log

---------- Post updated at 08:52 ---------- Previous update was at 08:45 ----------

Or you can use script command to make typescript of terminal session.
# 5  
Old 12-19-2012
Quote:
Originally Posted by bipinajith
How about:-
Code:
{
 set -v
 cd /root/;ls |grep .sh 
 lspci |grep 0000
} > collect_log

---------- Post updated at 08:52 ---------- Previous update was at 08:45 ----------

Or you can use script command to make typescript of terminal session.
I don't see "root@intel_5500_server:~#" and the command which run in the log it doesn't match what I want
# 6  
Old 12-19-2012
Did you try using script command? It will record everything printed on your screen including your shell prompt.
# 7  
Old 12-19-2012
Quote:
Originally Posted by bipinajith
Did you try using script command? It will record everything printed on your screen including your shell prompt.

I will try it, but set -v seems not make it.it's strange

---------- Post updated at 07:18 AM ---------- Previous update was at 07:14 AM ----------

Quote:
Originally Posted by bipinajith
Did you try using script command? It will record everything printed on your screen including your shell prompt.
seems "script" can't be used in the function in my script
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