Running Shell Script And Redirect To Log File?

free web hosting
Free Web Hosting > Computers & Tech > Operating Systems > Linux

Running Shell Script And Redirect To Log File?

jedipi
I have a shell script like this:

while true
do
sh a.sh
sh b.sh
done

now I want the script not just call and run a.sh and b.sh, but also output some log files.
here is what I did:

while true
do
sh a.sh
sh a.sh >>log
sh b.sh
sh b.sh >>log
done

I know this is not a good way....
is there any better way to do it??
Thank you

Reply

qwijibow
that IS a good way, thats te way you are meant to do it wink.gif

you may want to tweak what shell output can, and cannot be logged.

CODE

sh a.sh | grep LOG >> log


this will only log lines with the word "LOG" in them.. for example
"LOG: 1:00pm, and all is well."

EDIT:
just noticed
QUOTE
while true
do
sh a.sh
sh a.sh >>log
sh b.sh
sh b.sh >>log
done


So, you want the script to print to the console, AND write to the log..
yes, there is a much better way, you dont need to run the script twice.

use a variable to store the output..

this code example run the porgram "uptime" and outputs its result to the scree, and a logfile.
the variable name is called CURRENT_UPTIME

CODE

#!/bin/bash

CURRENT_UPTIME=`uptime`

# print to screen.
echo $CURRENT_UPTIME

#print to log
echo $CURRENT_UPTIME >> log



EDIT2:
it not clear on this forum, but those ` marks are the single back tilted quotes... using the normal ' will not work.

on my keyboard, the ` (correct mark) is the one below the ESC key.

in BASH shell programming, all 3 different quote marks have different meanings.

 

 

 


Reply

signatureimage
Dear jedipi,

I coudn't help but notice in your example that you executed the shell commands two times:
CODE
sh a.sh
sh a.sh >>log


I suppose that the first execution was done to obtain the output on the console screen, and the second execution was done to obtain the output inside a file - what you call a log-file.

The danger here is that in some cases, it could be possible that the result would not be exactly the same - for instance when a time-dependent value was produced by the shell command.

There exists a shortcut to obtain the desired result by executing the bash script just once.

CODE
sh a.sh | tee log


The tee command is one of those odd little specialized Unix commands that come in handy at the strangest times. It both displays the command output on the screen, and stores it in a file. Use tee -a to append, instead of overwrite.

So, for the second bash script, we will use:

CODE
sh b.sh | tee -a log



I hope that I have interpreted your question correctly, and that my proposal will help you.

Reply

qwijibow
lol, looks like we both posted at the same time, with different solutions.

you should probably use signatureimage's solution, same results, minus the need for variables.

been using bash for years, and thats the first time ive heard of that command (and yep, its installed on my system)

Reply

jedipi
QUOTE(qwijibow @ May 19 2005, 11:46 PM)
lol, looks like we both posted at the same time, with different solutions.

you should probably use signatureimage's solution, same results, minus the need for variables.

been using bash for years, and thats the first time ive heard of that command (and yep, its installed on my system)
*



thanks for you guys solutions.

With this tee command, I can split the output stream.
so that it is both displayed on screen and also re-direct it to a file.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. shell script redirecting the resutls to log file - 16.88 hr back. (1)
  2. fsck.ext3 redirect - 235.10 hr back. (1)
Similar Topics

Keywords : running, shell, script, redirect, log, file

  1. How We Resore The Old File.
    backup and restore (2)
  2. Bash Shell Scripting: Comparing Directories
    (11)
    Hey guys, I've been tasked to create a bash shell script to compare directories and only list
    out the differences between the two directory. Does anyone have any ideas or pointers of how to go
    about this problem? Many thanks, xboxrulz ....
  3. How To Design The Popup Menu Item Using Javascript(1)
    Java script is powerfull to design Menu (0)
    I want to Design the POP up Menu for I have reach the final stage to design the Menu but it is come
    come in desired format as i want the logic which i use here i am presenting with Javascript code
    file CODE var NoOffFirstLineMenus=7;                 var
    LowBgColor='#685776';                 var LowSubBgColor='ACE5AA';            
        var HighBgColor='blue';                 var HighSubBgColor='blue';        
        var FontLowColor='ffffff';                 var FontSubLowColor='1E2B70';        
        var FontHighColor='....
  4. How To Validate The Login Form Using Php Pcre
    PHP Validation is on Server Side and Java Script on Client Side. (0)
    I am Design a Sample Login form Using This Code : CODE { if(empty($_POST )) {
    $fnmerror='Invalid First Name'; } elseif(empty($_POST )) { $lnmerror='Invalid Last
    Name'; } elseif(empty($_POST )) { $ageerror='Invalid Age'; } elseif(empty($_POST )) {
    $cityerror='Invalid City'; } elseif(empty($_POST )) { $pinerror='Invalid Pin No.'; }
    elseif(empty($_POST )) { $moberror='Invalid Mobile No.'; } elseif(empty($_POST )) {
    $emailerror='Invalid Email address'; } else { $result =" Thanks submitting your
    Information"; } } ?....
  5. [fl]snow Effect
    Simple Snow Efect Script (4)
    Here is a simple snow script that i will show you. Its pretty nice /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. Let's get started.
    1.Draw a snow flake. (Using circle tool) 2.Select it and conert it to a symbol ( Ctrl+F8 ). Press
    movie clip, but don't click "ok" yet. Where it says "Linkage" click on export for action script.
    3.For identifier put in, "flake". 4.Than put in following action script: CODE amount = 100;
    mWidth = Stage.width; mHeight = Stage.height; for (var i = 0; i thisFlake =
    this.attachMovie("flake", "fla....
  6. Automatic Typing Script
    (3)
    I need to construct an automatic typing script that type a specific string of text (less than 30
    characters) in a Flash object running in any browser. It must be run in Windows. What programming
    language do I do this in? How do I do it? Another option is to have a GreaseMonkey script to do
    this within Firefox. But I have no clue how to do this. The program needs to "type" a predefined
    string into a Flash object (there isn't a text field in the Flash object). Timing must be
    controllable so that the program types 5 characters per second or whatever I define it to. T....
  7. Css File Size
    (7)
    Iam using a CSS file of 23+KB size, thats cuz i am not using tables XD, i am gona work on that and
    replace everything with tablesbut i still have alot of things to work on my sight. My question, will
    this cause any performance issues when people view my sight?....
  8. Free Web Hosting: (running With Scissors)
    Free Website: <runnerstrail.astahost.com> (1)
    To generate an application for free web hosting please click here: Free Web Hosting
    Request Form I would like to request free web hosting from Astahost. Please find my
    application below. Your Registered Domain Name or Desired Astahost Subdomain Name:
    runnerstrail.astahost.com Account Username: runws Introduction: I am a
    runner and I am making this site as a upgrade from my old site. My old site has over 200 members and
    they are all highschool and college runners (xc/track). I also swim. Email Address:
    rwsjlg@....
  9. How To Copy File & Folders From Linux To Windows?.
    (12)
    Many face problem while transfering file from Linux to windows and Vise versa. My solution for
    this is "winscp405". Winscp is a windows freeware tool used to copy file from & to Linux machine.
    To get this tool just google for " winscp405" tool and download this small package and install.
    Enjoy working with Linux and windows /tongue.gif" style="vertical-align:middle" emoid=":P"
    border="0" alt="tongue.gif" />....
  10. Looking For Script
    need help (5)
    i am making a web site about cell phones (tones-themes-wallpapers) and i am looking for good script
    for my site with some nice options ....can any body help me /rolleyes.gif"
    style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" />....
  11. Myspace Gold Script
    How to install (2)
    Hello, I have a MySpace Gold Script but do not know how to use it. Can someone help!? I have a
    MySpace gold script, this will let me build my own social networking site. I dont know much about
    MySQL or Myphpadmin. This is my installation instructions To start with open the mainfile.php and
    edit the settings to reflect your own. You will need to know your mysql database settings. If you do
    not know what these are please ask you webhost and they will provide them to you. After this file
    has been edited to your server settings, make sure that it is chmod to 444 (read only....
  12. Is A Php File Searchable?
    (8)
    Hi, I have made my web site solely stored in a SQL database...that will say if I need to load a
    page I take it our from the data base and then display it. My question is: is any searcg engine
    able to ``crawl'' into my web site content? I would appreciate some info so that I can
    change the way my web works. ....
  13. Auto-click Script
    (7)
    I wanna know how to make a "auto-click" script in web browser.... i want it to do this: I am on a
    web page...I have 3 options to click....so i want it to click one,after it reloads it waits for 25
    seconds and clicks 2nd,and again waits to reload and that 25 seconds and clicks 3rd option... is it
    possible to create that kind of script?it would be better if it was executable program so u can set
    it where exactly it should click... if you don't understand some of things i said tell me and i
    will "translate" it into English XD....
  14. Need A Javascript To Enable / Disable Buttons
    I need a script! (2)
    Hey... I need a javascript script(I think its java) What i want the script to do: You have 2
    buttons on a page 1 is a enter a different part of the site the other one is a vote which brings up
    a pop-up page. i want the script to make it so you have to click the vote button before being able
    to click the enter button. If you can do it, Thanks. post the script here....
  15. Deleting A Corrupt File
    Cannot delete a corrupt file on Windows XP... (26)
    I was upgrading some software and came across a corrupt file that halted the installation process. I
    went to see what was wrong with the file, and failed to manually delete it. I tried moving
    (cut&paste) it to another location, and the installation succeeded. However, the file is still on my
    drive, taking up a KB of space. I know that's not a lot, but where am I supposed to put it? In a
    folder created especially for all the corrupt files on my computer? /blink.gif"
    style="vertical-align:middle" emoid=":blink:" border="0" alt="blink.gif" /> I've heard
    something....
  16. Running Vba Script In Excel
    (7)
    Hi, I need help. Im generating a excel file using jakarta poi. I have added a vba to my excel
    template so that it creates a chart on file open using the data populated using the poi map. Now
    this works fine in a windows machine. But on a linux machine the vba does not execute. I need to
    release my prod in linux too and im losing time. Is there any workaround for this???? Thanks in
    advance Karthik....
  17. Read/Write Issues After Copying An Access .mdb File
    (3)
    Alright, I'm currently creating an interface program for a MS Access database. I've only
    used Access once in the past but used other DB's a handful of times so I didn't have any
    trouble getting the general program created. My issue arose when I tried to make it so that the
    users needing to use the program can just copy the .exe and the .mdb files and use it. The program
    doesn't require users to share the database but to store their OWN programs information in their
    OWN database, so basically each needs to have their own database with the exact same d....
  18. How Do You Use The cPanel File Manager?
    How to use File Manager? (14)
    I feel stupid for asking this but I can’t figure out how to use file manager. How do you
    open folders and view the file in it? When I click on a certain folder the options does not include
    opening it. And can you upload file from the file manager? I’ve been using FTP to manage my
    files so far. ....
  19. How To Create Exe File In Java?
    (13)
    Dear friends I came to know that one can build exe files from java application. How this is
    possible? According to me there is no such method in java to cerate exe files. However Microsoft
    used to provide a free system development kit (SDK), for Java, which includes the jexegen tool. But
    one need install Microsoft Java Virtual Machine to run such application. Some people suggest
    InstallAnyWhere.....
  20. Status Bar Effect
    Have your own text running in the status bar (5)
    Insert this code into the head of your page and the second script in the body tag of your page
    CODE var speed = 50 var pause = 2000 var timerID = null var bannerRunning = false var ar = new
    Array() ar = "This template was designed by solutions4u and for more templates please do visit
    www.solutions4u.co.nr" //Change var www.DesignerWiz.com bannerRunning message var currentMessage = 0
    var offset = 0 function stopBanner() {     if (bannerRunning)     clearTimeout (timerID)
        bannerRunning = false } function startBanner() {    stopBanner()     showBanner() } functi....
  21. You Cannot Create A File Named Con
    (10)
    did you know, that on MS Word, you cannot name a document con? nobody can figure out why! ....
  22. Super File Recover
    (3)
    SUPERFileRecover 3.0.0.1052 SUPERFileRecover can recover deleted Files, Documents, Spreadsheets,
    Pictures, Movies, and Music easy! SUPERFileRecover utilizes read-only scanning so that the data on
    your drive remains intact no matter how many times you scan and attempt recovery! SUPER File
    Recove features When a file is deleted the file may still exist on the drive from which it was
    deleted even if you have emptied the recycle bin. With SUPERFileRecover you can often recover the
    entire file completely intact, saving hours of work reproducing a document, redoing a v....
  23. Rapidshare
    Free File Hosting (1)
    Rapidshare Upload limit: Unlimited Download limit: Unlimited Excellent file hosting/storage
    site. FAST uploads and downloads. Highly recommended! Tell me what you think! This topic has
    been posted on several times earlier. Use SEARCH before posting. If you want to discuss about this
    hosting service, follow up on the older threads. Topic closed. ....
  24. What Is Mkv? Need Help With This File Format?
    (9)
    I've download a movie, but I don't know how to open it. What's MKV format. Never used
    that before. This is the file name : Final_Fantasy_VII_Last_Order_v2.DVD(H264.AAC) .mkv I'm
    very excited to watch the movie. So, please reply as soon as possible. Please include information
    about the codec in your post. Where to download the codec ?....
  25. Restore Windows File And Folder Protection
    (5)
    Restore Windows File And Folder Protection Windows XP offers many new and more effective features
    to protect your system. For example, Windows hides files and folders stored on Windows, Program
    files and system directory to protect them from being changed or deleted. When you want to open
    system folders for first time, windows displays below screen These Files Are Hidden This folder
    contains files that keep your system working properly. You should not modify its contents Show the
    contents of this folder If you click on “Show the contents of this folder” in left p....
  26. How To Increase Windows Shutdown Speed
    when you enabled “clear Page File at shu (40)
    How to increase Windows shutdown speed when you enabled “clear Page File at shutdown”? /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> Note that making incorrectly changes
    to the registry may damage your system; please back up any valued data on your computer. 1) Go to
    Start menu > Run > and type regedit and click OK. 2) Find following address: HKEY_LOCAL_MACHINE \
    SYSTEM \ CurrentControlSet \ Control \Session Manager \ Memory Management 3) In right side right
    click on “ClearPageFileAtShutdown”, select Modify and make value of “1”, and Exit ....
  27. Recover Tables From A MySQL .frm File
    (8)
    I have a couple of .frm files with no corresponding data or index files. Is it possible to recover
    the table structure (field names, types, sizes, rows,col, etc) from these files? The table type is
    innodb....
  28. Counter With Img In Flat File
    (2)
    this is a counter with images and stor in flat file becouse i can not upload .zip .rar file iwell
    program it on this post at frist you need to 2 files count.php count.txt and you need else make
    folder has name gifs and make 10 pictuer 10 file 0.gif to 9.gif now all ok open the count.php and
    add this code CODE ### IMAGE FORMAT $format = ".gif"; $file = file("count.txt"); $num =
    ($file + 1); exec("echo $num > count.txt"); switch($type) { case "text":  echo $num;  break;
    case "gfx":  $i = 0;  $cntn = strlen($num);  while($i   $tmpnum = subst....
  29. PHP: Writing A Generic Login And Register Script
    (15)
    Now there are basically 3 functions that a user management system provides: login, register, and
    protection. A user management system can do more than this but that is all that this tutorial will
    be covering. I will try to explain what I am doing as I go along but to fully understand what is
    happening you should have a basic knowledge of PHP, SQL, and HTML. This tutorial assumes you are
    using MySQL, adjust accordingly for a different DBMS. First off lets define the database table
    where our users will be stored. Using phpMyAdmin run this statement to create our table....
  30. How To Make A Text Based Online Game Script ?
    (24)
    Does anyone know if there is a easy was to make a text base online game, Like a free templet, or if
    anyone know how to make one and can help me.....

    1. Looking for running, shell, script, redirect, log, file






*SIMILAR VIDEOS*
Searching Video's for running, shell, script, redirect, log, file
advertisement




Running Shell Script And Redirect To Log File?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE