LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   save output of bash file (https://www.linuxquestions.org/questions/linux-software-2/save-output-of-bash-file-891076/)

sysmanz 07-11-2011 07:08 AM

save output of bash file
 
Hi Guys,

I've shell bash file script and I want to save the output into a txt file.
I Know ./bash.sh > output.txt will save the result into a file but i want to add something into a bash file and then when the bash file process completed, it save the result into a file and I don't want that overwrite the output into the old file, I want each time i run it, it save the result into a new file.
How can i do that ?!

Thanks

tredegar 07-11-2011 07:22 AM

You need to create a new filename each time you want the log saved.
You can easily do this with date

date +%s gives the number of seconds since 1970-01-01 00:00:00 UTC

Sample code:
Code:

LOGFILE=logfile-$(date +%s)
./bash.sh > $LOGFILE


sysmanz 07-11-2011 07:30 AM

Quote:

Originally Posted by tredegar (Post 4411512)
You need to create a new filename each time you want the log saved.
You can easily do this with date

date +%s gives the number of seconds since 1970-01-01 00:00:00 UTC

Sample code:
Code:

LOGFILE=logfile-$(date +%s)
./bash.sh > $LOGFILE


It works but the result is not what i want.
The logfile created and its contain :
Code:

Usage: ./domain-check [ -e email ] [ -x expir_days ] [ -q ] [ -a ] [ -h ]
          {[ -d domain_namee ]} || { -f domainfile}

  -a              : Send a warning message through email
  -d domain        : Domain to analyze (interactive mode)
  -e email address : Email address to send expiration notices
  -f domain file  : File with a list of domains
  -h              : Print this screen
  -s whois server  : Whois sever to query for information
  -q              : Don't print anything on the console
  -x days          : Domain expiration interval (eg. if domain_date < days)

But the output is something like this and I need to see this result into logfile :
Code:

roghan@Nabati:~$ ./domain-check -d yahoo.com

Domain                              Registrar        Status  Expires    Days Left
----------------------------------- ----------------- -------- ----------- ---------
yahoo.com                          MARKMONITOR INC.  Valid    19-jan-2012  192

Sorry.. I'm newbie in this case..

TobiSGD 07-11-2011 07:33 AM

Then you have made a mistake with the options for your shell-script. Please post the exact command you used and also how you use the program when you don't create a logfile.

sysmanz 07-11-2011 07:41 AM

Quote:

Originally Posted by TobiSGD (Post 4411517)
Then you have made a mistake with the options for your shell-script. Please post the exact command you used and also how you use the program when you don't create a logfile.

I think I'm not.
Its the script url http://www.cyberciti.biz/files/scrip...in-check-2.txt
And i use it like this ./domain-check -d yahoo.com
I added the code tredegar gaves to me and it make the logfile itself but the result is not what i want.
I want the shell script output into a file.

Regards

MTK358 07-11-2011 08:26 AM

Did you try it like this:

Code:

logfile=logfile-$(date +%s)
./domain-check -d yahoo.com > $logfile

?

tredegar 07-11-2011 08:26 AM

Code:

./domain-check  -d  yahoo.com  >  logfile-$(date +%s)
Should do it.


All times are GMT -5. The time now is 04:24 PM.