Unix Technical Forum

[OT] A quick bash query > histories

This is a discussion on [OT] A quick bash query > histories within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Off and on, over the holidays, I've been trying to find a way to save the bash history from ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2008, 01:51 PM
No_One
 
Posts: n/a
Default [OT] A quick bash query > histories

Off and on, over the holidays, I've been trying to find a way to save the
bash history from each tty that I open to a seperate file. I may have 9
ttys open under the same user name, however, I can find no way to save the
history files according to the tty as opposed to the user....anyone know of
a way.

ken
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2008, 01:51 PM
Grant
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

On Wed, 04 Jan 2006 22:20:53 GMT, No_One <no_one@no_where.com> wrote:

>Off and on, over the holidays, I've been trying to find a way to save the
>bash history from each tty that I open to a seperate file. I may have 9


Are you relying on "!something" to work? --> alias candidate for no_one

After uparrow history per terminal? --> no_one1, no_one2, ... users
with appropriate symlinks to common files, directories. messy
Perhaps even crazy?

Grant.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 01:52 PM
No_One
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

On 2006-01-04, Grant <bugsplatter@gmail.com> wrote:
>
> After uparrow history per terminal? --> no_one1, no_one2, ... users
> with appropriate symlinks to common files, directories. messy
> Perhaps even crazy?
>
> Grant.


Thanks, I figured out a solution last night...in the /home/kenneth/.bashrc


TTYSCREEN=$(tty|sed s-/dev/tty--)
HISTFILE=/home/kenneth/$TTYSCREEN.history
EXPORT HISTFILE

Sets a default and seperate history file for each tty I open as user kenneth

ken
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-20-2008, 01:52 PM
Eef Hartman
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

No_One <no_one@no_where.com> wrote:
> TTYSCREEN=$(tty|sed s-/dev/tty--)


Note: that doesn't work on X-windows "terminals" as they are
pts/nn (pseudo terminal stream, with a number):
$ who am i
hartman pts/4 Jan 5 15:26
so NOT a tty (those are only the text console and dial-in modems.

So you also must test on /dev/pts/<some number> and give it a
DIFFERENT history file from the tty ones.
--
************************************************** ******************
** Eef Hartman, Delft University of Technology, dept. EWI/TW **
** e-mail: E.J.M.Hartman@math.tudelft.nl, fax: +31-15-278 7295 **
** snail-mail: P.O. Box 5031, 2600 GA Delft, The Netherlands **
************************************************** ******************
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-20-2008, 01:52 PM
No_One
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

On 2006-01-05, Eef Hartman <E.J.M.Hartman@math.tudelft.nl> wrote:
> No_One <no_one@no_where.com> wrote:
>> TTYSCREEN=$(tty|sed s-/dev/tty--)

>
> Note: that doesn't work on X-windows "terminals" as they are
> pts/nn (pseudo terminal stream, with a number):
> $ who am i
> hartman pts/4 Jan 5 15:26
> so NOT a tty (those are only the text console and dial-in modems.
>
> So you also must test on /dev/pts/<some number> and give it a
> DIFFERENT history file from the tty ones.


You're right, of course...however tty will report /dev/pts/n etc. I guess the
best solution would be something like:

if $DISPLAY != ":0.0" parse the tty number one way
else parse it another way

ken

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-20-2008, 01:52 PM
Eef Hartman
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

No_One <no_one@no_where.com> wrote:
> if $DISPLAY != ":0.0" parse the tty number one way
> else parse it another way


Better to test on "pts" in the result from "tty", as remote logins
(ssh, rsh, telnet) will also be on pts's (and the latter two do not
have got DISPLAY set by default, ssh will when X-forwarding has been
enabled). So something like
if tty|grep -q "pts"
then HISTFILE=".bash_history-pts`tty|sed "s#/dev/pts/##"`
else HISTFILE=".bash_history-tty`tty|sed "s#/dev/tty##"`
fi
will probably work.

As far as I known the old pty's (pseudo terminals, sort of a predecessor
to pts streams) aren't used anymore, but if you want to make sure,
you could add an extra test for those:
elif tty|grep -q "pty"
then HISTFILE=".bash_history-pty`tty|sed "s#/dev/pty##"`
(before the "else" in the above condition).

But by then it is probably useful to run "tty" just once and store
the result, instead of keeping on invoking it.
--
************************************************** ******************
** Eef Hartman, Delft University of Technology, dept. EWI/TW **
** e-mail: E.J.M.Hartman@math.tudelft.nl, fax: +31-15-278 7295 **
** snail-mail: P.O. Box 5031, 2600 GA Delft, The Netherlands **
************************************************** ******************
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-20-2008, 01:54 PM
No_One
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

On 2006-01-06, Eef Hartman <E.J.M.Hartman@math.tudelft.nl> wrote:
> No_One <no_one@no_where.com> wrote:
>> if $DISPLAY != ":0.0" parse the tty number one way
>> else parse it another way

>
> Better to test on "pts" in the result from "tty", as remote logins
> (ssh, rsh, telnet) will also be on pts's (and the latter two do not
> have got DISPLAY set by default, ssh will when X-forwarding has been


<deleted>

>
> But by then it is probably useful to run "tty" just once and store
> the result, instead of keeping on invoking it.


I appreciate the addtional information...saved for this weekend's Linux
project, one of several....again thanks.

ken
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-20-2008, 01:58 PM
Chris Green
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

On 2006-01-05, No_One <no_one@no_where.com> wrote:
> On 2006-01-05, Eef Hartman <E.J.M.Hartman@math.tudelft.nl> wrote:
>> No_One <no_one@no_where.com> wrote:
>>> TTYSCREEN=$(tty|sed s-/dev/tty--)

>>
>> Note: that doesn't work on X-windows "terminals" as they are
>> pts/nn (pseudo terminal stream, with a number):
>> $ who am i
>> hartman pts/4 Jan 5 15:26
>> so NOT a tty (those are only the text console and dial-in modems.
>>
>> So you also must test on /dev/pts/<some number> and give it a
>> DIFFERENT history file from the tty ones.

>
> You're right, of course...however tty will report /dev/pts/n etc. I guess the
> best solution would be something like:
>
> if $DISPLAY != ":0.0" parse the tty number one way
> else parse it another way
>

Definitely
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:39 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com