LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2009, 05:07 PM   #16
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by computer_freak_8 View Post
Maybe add in an "exit" command at the end of "~/.bashrc"? I'll try that here soon...
Nope. No such luck.

Seriously, though: Is there a Bash variable for the given command? If there is, I'm guessing that would be much easier.
Okay, I realize this may not be clear, so let me try to give a scenario and see if this makes any sense. Note: I don't know if anything like this would work or not; this is just my try at explaining how I think I could get this to work, in theory.

1. I give the command "sudo apt-get update"
2. Bash stores this temporarily in the variable "$command"
3. Instead of just executing the command, Bash sees a section in my "~/.bashrc" file, and pipes the command to it.

The section would be (pseudo-code) something like:
Code:
{
print "$command" >> logfile.txt  # append the command to the log
print "\n" >> logfile.txt  # append a newline after the command
$command | tee -a logfile.txt  # output to the file and the screen
print "\n\n" >> logfile  # append two newlines to the logfile, to make it more legible
}
****Edit: Looking here, is that what "$FUNCNAME" does? I just now found that link. I'm going to try it here soon.****

Last edited by computer_freak_8; 02-02-2009 at 05:09 PM. Reason: Add information.
 
Old 02-02-2009, 06:59 PM   #17
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Alternately, put that in a shell script eg my_apt-get.sh and set sudo to only allow that cmd.
 
Old 02-02-2009, 08:46 PM   #18
computer_freak_8
Member
 
Registered: Jul 2008
Location: Iowa
Distribution: Ubuntu and Fedora, mostly
Posts: 89

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Alternately, put that in a shell script eg my_apt-get.sh and set sudo to only allow that cmd.
That would work on a per-command basis. What I'm looking for is something that will log all commands and their output.
[ - time passage - ]
Alright, I just about have it! Here's what I've gotten so far:
Code:
while true
do {
TTY=`tty`
echo '###############jaredtbrees' >> /home/jaredtbrees/terminallog.txt
echo "$TTY" >> /home/jaredtbrees/terminallog.txt
read -p "$USERNAME@$HOSTNAME:$PWD$ " COMMAND
echo "$COMMAND >> /home/jaredtbrees/terminallog.txt
echo -e "\n" >> /home/jaredtbrees/terminallog.txt
$COMMAND | tee -a /home/jaredtbrees/terminallog.txt
echo -e "\n\n" >> /home/jaredtbrees/terminallog.txt
}
done
(Note: There may be typographical errors. I tried this on another computer and am switching the monitor's input back and forth. I would have used a flash drive to transfer it, but apparently the USB ports are not working...)
This bit of code gives me all that I need, and then some... except one thing: when I am in the home directory, I would like it to be displayed as "~" instead of "/home/username".

Now does it make sense? If I could just get that one last bit...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
.bashrc personal environment variable hua Linux - Software 1 04-11-2008 04:12 AM
create a variable in the .bashrc file in my home directory coldbeerz Linux - Newbie 2 12-14-2007 10:48 AM
bashrc variable ovince Programming 1 04-25-2007 08:35 AM
how to add environment variable to .bashrc file hasan Linux - General 7 10-03-2003 05:43 PM
how to add environment variable to .bashrc file? hasan Red Hat 1 10-03-2003 02:37 PM


All times are GMT -5. The time now is 02:43 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration