Lose your terminal session? Did your VPN drop? Did you have a bunch of work you were doing in your bash session and because you lost connection, your session closed uncleanly and you wanted to retrieve your command history?
Yeah. Sucks, huh?
Here's a simple fix:
insert the following in your ~/.bashrc :
# vi ~/.bashrc
export PROMPT_COMMAND='history -a'
and resource:
# .~/.bashrc
There.
Now your commands will "flush" to the history file immediately.
You're welcome.
-Wrex
Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts
Friday, June 20, 2014
Monday, September 30, 2013
Recover a file with LSOF....
Just a quick and dirty of how to recover a file in LSOF.
lsof (List Open Files) is a *nix tool that will show open files and network connections. Of course, it's also available for OS X.
You can recover deleted files with it.
If you have ever deleted a file by mistake you can recover the deleted file.
For example, to recover a missing messages log used by Syslog you can search for it via this command:
bash:~ lsof | grep messages
You should see something similar to:
syslogd 15328 root 2w REG 253,2 1419873 983175 /var/log/messages.5 (deleted)
You want to find what is marked as deleted in parenthesis. The process (15328) still has the file open. Without this process keeping the file open we would have lost the file permanently. This is important. Once the process stops, you won't be able to trace the file this way, so avoid rebooting or stopping the process entirely, until after you've recovered the lost file.
We can view the missing info by looking inside the proc filesystem, the process id (15328), and in the file descriptor (fd). The fd is found in the 4th entry, above (2w in this example):
We can view the missing info by looking inside the proc filesystem, the process id (15328), and in the file descriptor (fd). The fd is found in the 4th entry, above (2w in this example):
bash:~ cat /proc/15328/fd/2
This outputs the contents the deleted messages.5 file. As you can see, the data is still there. Now, just redirect the contents back to /var/log/messages.5:
bash:~ cat /proc/15328/fd/2 > /var/log/messages.5
That's all there is to it. You have recovered the file with all the data back to its original location. You should also restart the process, writing to the file(s) recovered.
This is just one of many examples of how lsof can be very useful. Be sure to check out the Man pages and other docs.
Labels:
file recovery,
linux,
List Open Files,
lsof,
Mac OS X,
mac osx,
os x,
osx,
process management,
recover missing files,
Solaris,
Unix
Sunday, June 10, 2012
So you want a fresh Ubu install and don't want to hunt-down all you currently packages....
..and reinstall them all one-by-one or write a silly script to handle them all. Well, here's a simple solution:
Save currently installed packages:
# dpkg --get-selections > packages.installed
Save this off and then copy to new machine or back to re-installed, then do:
# dpkg --set-selections < packages.installed
(* Note: You may want to prune the list of software that you don't want to install or is incompatible if newer version of OS, before doing import above.)
Then do: # dselect
Also, don't forget to save and copy over your /etc/apt/sources.list of course.
That's it! Simple, eh?
Save currently installed packages:
# dpkg --get-selections > packages.installed
Save this off and then copy to new machine or back to re-installed, then do:
# dpkg --set-selections < packages.installed
(* Note: You may want to prune the list of software that you don't want to install or is incompatible if newer version of OS, before doing import above.)
Then do: # dselect
Also, don't forget to save and copy over your /etc/apt/sources.list of course.
That's it! Simple, eh?
Labels:
/etc/apt,
/etc/apt/sources,
apt,
apt-get,
BSD,
dpkg,
dselect,
install,
linux,
packages,
software,
sources.list,
Ubuntu,
Ubuntu 11.10,
Ubuntu 12.01,
uninstall,
Unix
Wednesday, March 05, 2008
Using Sprint EVDO card (S620) in Linux
Some quick/dirty notes in getting your Sprint S620 EVDO card working in Linux (I am currently using Fedora FC8):
Note Sprint S620 card vendor ID is 1410 and product is 1110. You can ascertain this by the following (as root):
[root@localhost ~]# cat /proc/bus/usb/devices
T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1410 ProdID=1110 Rev= 0.00
S: Manufacturer=Novatel Wireless Inc.
S: Product=Novatel Wireless Merlin CDMA
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=usbserial_generic
E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=128ms
E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
I: If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=usbserial_generic
E: Ad=84(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
As root:
Check to see if module loaded:
[root@localhost ~]# modprobe uhci-hcd
[root@localhost ~]# modprobe ohci-hcd
[root@localhost ~]# modprobe usbserial vendor=0x1410 product=0x1110
Unload Module (Some reason, it wouldn't work, until I removed it, first):
[root@localhost ~]# modprobe -r usbserial
[root@localhost ~]# modprobe -r ehci-hcd
[root@localhost ~]# modprobe -r ohci-hcd
Re-load OHCI and probe for card again:
[root@localhost ~]# modprobe ohci-hcd
[root@localhost ~]# modprobe usbserial vendor=0x1410 product=0x1110
mknod the device you are going to dial through:
[root@localhost ~]# mknod /dev/ttyUSB0 c 188 0
Now set up your favorite PPP dialer (I use kppp, myself) and have phun.
Note Sprint S620 card vendor ID is 1410 and product is 1110. You can ascertain this by the following (as root):
[root@localhost ~]# cat /proc/bus/usb/devices
T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1410 ProdID=1110 Rev= 0.00
S: Manufacturer=Novatel Wireless Inc.
S: Product=Novatel Wireless Merlin CDMA
C:* #Ifs= 2 Cfg#= 1 Atr=a0 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=usbserial_generic
E: Ad=81(I) Atr=03(Int.) MxPS= 64 Ivl=128ms
E: Ad=82(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=02(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
I: If#= 1 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=usbserial_generic
E: Ad=84(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=04(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
As root:
Check to see if module loaded:
[root@localhost ~]# modprobe uhci-hcd
[root@localhost ~]# modprobe ohci-hcd
[root@localhost ~]# modprobe usbserial vendor=0x1410 product=0x1110
Unload Module (Some reason, it wouldn't work, until I removed it, first):
[root@localhost ~]# modprobe -r usbserial
[root@localhost ~]# modprobe -r ehci-hcd
[root@localhost ~]# modprobe -r ohci-hcd
Re-load OHCI and probe for card again:
[root@localhost ~]# modprobe ohci-hcd
[root@localhost ~]# modprobe usbserial vendor=0x1410 product=0x1110
mknod the device you are going to dial through:
[root@localhost ~]# mknod /dev/ttyUSB0 c 188 0
Now set up your favorite PPP dialer (I use kppp, myself) and have phun.
Thursday, November 30, 2006
UNIX: Simple one-liner to chop last field from file
So, I wanted to chop off the last field in a file extension (bob.joy.txt, for example).
Here's is a simple solution, using reverse (rev), ls, cut and a for loop:
for i in `ls *.txt`; do mv $i `echo $i|rev |cut -d '.' -f2-|rev`;done
There's prob a cleaner way, but this was quick and easy.
Here's is a simple solution, using reverse (rev), ls, cut and a for loop:
for i in `ls *.txt`; do mv $i `echo $i|rev |cut -d '.' -f2-|rev`;done
There's prob a cleaner way, but this was quick and easy.
Sunday, September 03, 2006
Veritas Cluster GUI 4.x in OSX howto
I hacked this together, so I can run the VCS cluster GUI on my Mac, instead of relying on Winbloze. I am almost ready to dump MicroCrap altogether! :-)
I'll be working on the VEA gui, later.
While I prefer command-line, sometimes a GUI is still nice. Especially, in a complex cluster arrangement, such as the one I admin.

Veritas Cluster Manager 4.x in Mac OS X
Configuring the Veritas Cluster Manager to use the Mac OS X using OS X native Java.
1- Copy the Veritas GUI from server (/opt/VRTSvcs/gui) to a location of choice on your Mac.
2- Edit hagui script (this script, below) to reflect the location of VRTSvcs and the path to your JAVA Home
3- Open a terminal and run /path/to/VRTSvcs/hagui
The following is a copy of the modified hagui script (modify to your liking):
**************************************************************
#!/bin/sh
#
# START COPYRIGHT-NOTICE: 1998, 2003
#
# Copyright 1998, 2003 VERITAS Software Corporation.
# All rights reserved.
#
# VERITAS, VERITAS SOFTWARE, the VERITAS logo and all other VERITAS
# product names and slogans are trademarks or registered trademarks
# of VERITAS Software Corporation in the USA and/or other countries.
# Other product names and/or slogans mentioned herein may be trade-
# marks or registered trademarks of their respective companies.
#
# END COPYRIGHT-NOTICE.
#
# change the environment's classpath and
# java_home
#unset JAVA_HOME
#unset CLASSPATH
PATH=".:$PATH"
export PATH
#VCS_HOME="/opt/VRTSvcs"
VCS_HOME="/Users/wallen/VRTSvcs"
#JAVA_HOME=$VCS_HOME/gui/jre
LIB_PATH=$VCS_HOME/gui/lib
LANG_PATH=$VCS_HOME/gui/lang
LD_LIBRARY_PATH=$LIB_PATH
export LD_LIBRARY_PATH
BCLASSPATH=${LANG_PATH}:${LIB_PATH}/VCSGui.jar:${LIB_PATH}/gui_images.jar:${LIB_PATH}/sounds.jar:${LIB_PATH}/VxHelpViewer.jar:${LIB_PATH}/VxHelpViewerl10n.jar
DEBUG=0
if [ "$1" = "-D" ] ; then
DEBUG=1
shift 1
fi
if [ "$#" = 0 ] ; then
if [ "$CSGA_DIR" = "" ] ; then
CONF_PATH=$VCS_HOME/gui/
else
CONF_PATH=$CSGA_DIR
fi
elif [ "$#" = 1 ] ; then
CONF_PATH=$*
shift 1
elif [ "$#" -gt 1 ] ; then
if [ -d "$1" ] ; then
CONF_PATH=$1
shift 1
elif [ "$1" != "-h" ] && [ "$1" != "-p" ] ; then
echo "$1: configuration directory doesn't exist."
exit 1
fi
else
echo "$SELFNAME: configuration directory is incorrect!"
exit 1
fi
CLASSPATH=${CONF_PATH}:$BCLASSPATH:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/i18n.jar
export CLASSPATH
if [ $DEBUG = 0 ] ; then
exec $JAVA_HOME/bin/java -Dbase.dir="/opt/VRTSvcs/gui" -classpath $CLASSPATH -mx128m VCSGui $* > /dev/null
else
exec $JAVA_HOME/bin/java -Dbase.dir="/opt/VRTSvcs/gui" -classpath $CLASSPATH -mx128m VCSGui $*
fi
I'll be working on the VEA gui, later.
While I prefer command-line, sometimes a GUI is still nice. Especially, in a complex cluster arrangement, such as the one I admin.

Veritas Cluster Manager 4.x in Mac OS X
Configuring the Veritas Cluster Manager to use the Mac OS X using OS X native Java.
1- Copy the Veritas GUI from server (/opt/VRTSvcs/gui) to a location of choice on your Mac.
2- Edit hagui script (this script, below) to reflect the location of VRTSvcs and the path to your JAVA Home
3- Open a terminal and run /path/to/VRTSvcs/hagui
The following is a copy of the modified hagui script (modify to your liking):
**************************************************************
#!/bin/sh
#
# START COPYRIGHT-NOTICE: 1998, 2003
#
# Copyright 1998, 2003 VERITAS Software Corporation.
# All rights reserved.
#
# VERITAS, VERITAS SOFTWARE, the VERITAS logo and all other VERITAS
# product names and slogans are trademarks or registered trademarks
# of VERITAS Software Corporation in the USA and/or other countries.
# Other product names and/or slogans mentioned herein may be trade-
# marks or registered trademarks of their respective companies.
#
# END COPYRIGHT-NOTICE.
#
# change the environment's classpath and
# java_home
#unset JAVA_HOME
#unset CLASSPATH
PATH=".:$PATH"
export PATH
#VCS_HOME="/opt/VRTSvcs"
VCS_HOME="/Users/wallen/VRTSvcs"
#JAVA_HOME=$VCS_HOME/gui/jre
LIB_PATH=$VCS_HOME/gui/lib
LANG_PATH=$VCS_HOME/gui/lang
LD_LIBRARY_PATH=$LIB_PATH
export LD_LIBRARY_PATH
BCLASSPATH=${LANG_PATH}:${LIB_PATH}/VCSGui.jar:${LIB_PATH}/gui_images.jar:${LIB_PATH}/sounds.jar:${LIB_PATH}/VxHelpViewer.jar:${LIB_PATH}/VxHelpViewerl10n.jar
DEBUG=0
if [ "$1" = "-D" ] ; then
DEBUG=1
shift 1
fi
if [ "$#" = 0 ] ; then
if [ "$CSGA_DIR" = "" ] ; then
CONF_PATH=$VCS_HOME/gui/
else
CONF_PATH=$CSGA_DIR
fi
elif [ "$#" = 1 ] ; then
CONF_PATH=$*
shift 1
elif [ "$#" -gt 1 ] ; then
if [ -d "$1" ] ; then
CONF_PATH=$1
shift 1
elif [ "$1" != "-h" ] && [ "$1" != "-p" ] ; then
echo "$1: configuration directory doesn't exist."
exit 1
fi
else
echo "$SELFNAME: configuration directory is incorrect!"
exit 1
fi
CLASSPATH=${CONF_PATH}:$BCLASSPATH:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/i18n.jar
export CLASSPATH
if [ $DEBUG = 0 ] ; then
exec $JAVA_HOME/bin/java -Dbase.dir="/opt/VRTSvcs/gui" -classpath $CLASSPATH -mx128m VCSGui $* > /dev/null
else
exec $JAVA_HOME/bin/java -Dbase.dir="/opt/VRTSvcs/gui" -classpath $CLASSPATH -mx128m VCSGui $*
fi
Subscribe to:
Posts (Atom)