Standard script output to screen & -x option output to file
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Standard script output to screen & -x option output to file
Hi all,
Well, here I am. Close to 50 years old, new to scripting and first post. (Ironically sitting in front of the TV watching New Tricks). But I digress, so to business...
Someone has written for me a bash script running under Cygwin that uses wget and http (and more)to send commands to, and get responses from, a web-based system. I have written a basic wrapper script for it to make it more user friendly (i.e. present a menu etc.) and I used the -x option a lot when developing my wrapper script to be able to view the http responses from the system. I would now like to have a log file created that contains the information shown by -x when a user runs my script, but I don't want it echoed to the screen.
To summarise: Standard script output to the screen and -x output to a file.
Is there a way to do this? My investigations so far show that it may not, so I am willing to consider other methods of debug output to file.
if it's just the echo statement itself you want logged, within the script file just add ">> /path/file" to the end of the line that echos this to the screen.
echo "my line" >> /path/file
where path and file are replaced by the actual path and file you wish to log this in.
Last edited by r3sistance; 05-08-2011 at 07:09 AM.
r3sistance, my script is a bit large to make the suggested addition to the end of every line I want echoed to the log file, but I will keep it in mind for future use.
grail, I tried both of your suggestions and found that they both do almost does what I want. I tested using this:
However, I realise now that I was not as clear in my original post as I should have been. Using the test code above, the "read" prompt is output to the log file and the user doesn't get to see it. Is there a way that the prompts can be sent to stdout as well as the log file?
Is there a way that the prompts can be sent to stdout as well as the log file?.
I do not know how to redirect the prompts but yes you can very well redirect the variables (which has the prompt answers).
I think this can serve your purpose.
I'm getting close but I'll need to play around with all the suggestions to get exactly what I need. I'll be travelling for a while now, so I'll get back to you with results after further testing and when I can. This post is just to say thanks, I appreciate your answers and I just didn't want to leave you without a response and thanks until I can get back to the forum.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.