LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2016, 08:39 PM   #1
gctaylor1
Member
 
Registered: Dec 2006
Distribution: Red Hat
Posts: 45

Rep: Reputation: 0
Bash: Capture command line to file?


I have a long command line that I want to capture to a log file every time it is run? How do I this?

This not the exact command line but close enough. I've tried many permutations of this.
Code:
FILE=/tmp/params.txt ; date &>> $FILE; ls &>> $FILE; uptime &>> $FILE ; echo "${@}" &>> $FILE &
My file has the output of the commands but not the actual command line. Are my expectations incorrect about being able to do this?

Thanks,
Gary
 
Old 09-08-2016, 08:57 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I have a little function that I put in scripts that need to do that:
Code:
function run() {          # Display a command and run it
    echo "${PS4}$*" >&2
    PS4="+$PS4" "$@"
}
Commands for which I want to see that output are executed with
Code:
run some_command [options] arg_1 arg_2 ...
The output mimics the way the "-x" in bash displays nested commands, with the output going to stderr.
 
  


Reply

Tags
bash, redirection



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Call each line in a file as an argument to another command in Bash pradeepspa Linux - Newbie 15 07-19-2016 02:06 PM
[SOLVED] [bash]difference between script on command line and in file Wim Sturkenboom Programming 4 09-08-2008 02:20 AM
how do i create an empty bash(.sh) file in command line? bbmak Linux - Newbie 1 10-26-2007 02:39 AM
Screen capture using Mplayer command line lovalixir Linux - Software 1 12-04-2005 07:57 PM
Capture command line entry with timestamp moxshax Linux - Newbie 3 03-26-2004 03:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration