Personal HowTos & Configurations

linux sysadmin journal by vibranze

Nov
30

ESX Command Line - Go into Maintenance Mode

Filed Under Configurations

vimsh -n -e /hostsvc/maintenance_mode_enter

vimsh -n -e /hostsvc/maintenance_mode_exit

Nov
12

Simple HTTP Server with Python

Filed Under Configurations

python -m SimpleHTTPServer {optional port#} > $HOME/logfile.txt &

Jul
14

Mount Bin/Cue Files in Linux

Filed Under Linux

$ apt-get install bchunk

$ bchunk image.bin image.cue image.iso

$ mount -o loop -t iso9660 image.iso /mnt/image

Jul
24

Vi, delete everything after and including the comma

Filed Under Linux

:%s/^\(.*\),.*/\1/g

Apr
7

centos 5 default vimrc

Filed Under Configurations

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=utf-8,latin1
endif

set nocompatible        " Use Vim defaults (much better!)
set bs=indent,eol,start         " allow backspacing over everything in insert mode
"set ai                 " always set autoindenting on
"set backup             " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
                        " than 50 lines of registers
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  " In text files, always limit the width of text to 78 characters
  autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

if &term=="xterm"
     set t_Co=8
     set t_Sb=^[[4%dm
     set t_Sf=^[[3%dm
endif

Apr
7

disable beep sound in ubuntu

Filed Under Configurations

sudo modprobe -r pcspkr

Apr
3

vmware server start/stop script

Filed Under Configurations

- vmstart.bat:

net start "VMWare Authorization Service"
net start "VMWare DHCP Service"
net start "VMWare NAT Service"
net start "VMWare Registration Service"
net start "VMWare Virtual Mount Manager Extended"
"C:\Program Files\VMware\VMware Server\vmware.exe

- vmstop.bat:

net stop "VMWare Registration Service"
net stop "VMWare Authorization Service"
net stop "VMWare DHCP Service"
net stop "VMWare NAT Service"
net stop "VMWare Virtual Mount Manager Extended"
 

Mar
31

Export/Import Putty Setting

Filed Under Configurations

to export : regedit /e putty.reg HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

to import : regedit /s putty.reg or double click on putty.reg 

Dec
6

Install Notes 7.0.2 on a USB drive

Filed Under Configurations

setup /a /v"NOMAD=1 TARGETDIR=F:\ /qb+"

Nov
7

rpm, extract 1 file

Filed Under Configurations

rpm2cpio httpd-2.0.40-21.i386.rpm | cpio -ivd ./usr/bin/htpasswd

Nov
7

rpm, query & removing multiple packages

Filed Under Configurations

rpm -qa –qf '%{name}_%{version}-%{release}.%{arch}\n' | grep packages-name

rpm -e –nodeps –allmatches packages-name

Oct
16

send email with attachment from command line

Filed Under Configurations

mail -s "Subject" -a file1.tar.gz -a file2.tar.gz emailid@domain

or

mutt -s "Subject" -a file1.tar.gz -a file2.tar.gz emailid@domain

Jun
6

awk one liner, remove duplication line

Filed Under Configurations

awk ‘!x[$0]++’ file.old > file.new

Jun
6

sed, substitution example

Filed Under Configurations

sed -i ’s#net use N: \\.*#net use N: \\\\10.20.30.40\\shared /user:user password /persistent:no#g’ *.cmd

Mar
7

vi, delete blank lines

Filed Under Configurations

:g/^$/ d

Feb
5

Vi, Turn Entire File to Lower Case

Filed Under Configurations

Turn Entire File to Lower Case:

:%s/.*/\L&/

http://www.vmunix.com/~gabor/vi.html

Jan
18

Get Rid of ^M Using Vi

Filed Under Configurations

vi file.txt

:%s/^M//g

To get the ^M hold the control key, press V then M (Both while holding the control key).

Jan
11

Create Iso Files

Filed Under Configurations

mkiso -r -o file.iso /sourcedir

Jan
11

Apt-* Segmentation Fault Workaround

Filed Under Configurations

1. cd /var/cache/apt
2. rm -f *.bin

Sep
12

rar a file with volume 14mb to upload to gmail

Filed Under Configurations

$ rar a -m5 -v13312k output.rar source

Sep
6

/etc/init.d/motion

Filed Under Configurations

#!/bin/sh
# Description : Starts and stops an video survey
#/etc/rc.d/init.d/motion

MOTION_CONFIG_FILE=/home/nlshlt/.motion/motion.conf

. /etc/rc.d/init.d/functions

case “$1″ in

start)
KIND=”MOTION”
echo -n $”Starting $KIND services: ”
#modprobe videodev
#sleep 5
#modprobe stv680
#sleep 2
daemon /usr/bin/motion -c /home/nlshlt/.motion/motion.conf
echo
;;

stop)
KIND=”MOTION”
echo -n $”Shutting down $KIND services: ”
killproc /usr/bin/motion
#sleep 4
#rmmod stv680
#sleep 2
#rmmod videodev
echo
;;

status)
status /usr/bin/motion
;;

restart)
killproc /usr/bin/motion
daemon /usr/bin/motion -c /home/nlshlt/.motion/motion.conf
;;

*) echo “Usage: $0 { start,stop,status,restart}”
exit 1
esac
exit 0

Aug
31

convert any video file to DVD with open source tools

Filed Under Configurations

Converting the files to MPEG-2

First, you must convert your file to MPEG-2 for the video and to AC3 for the audio, in order to be compliant with the DVD video specifications. If the audio on your file is already encoded in AC3 format, you can use it as is without re-encoding it. Run this command to check the audio format of the file:

mplayer -vo dummy -ao dummy -identify your_video.avi 2>&1 | grep AUDIO_FORMAT | cut -d '=' -f 2

If it returns hwac3, the audio part of your file is encoded in AC3, and you can convert the file to MPEG-2 with the following command:

mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9
-ofps 25 -o your_video.mpg your_video.avi

If it isn’t encoded in AC3, run this command:

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,harddup
-srate 48000 -af lavcresample=48000
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9:
acodec=ac3:abitrate=192 -ofps 25 -o your_video.mpg your_video.avi

The previous commands create an MPEG-2 file in phase-alternating line (PAL) format with an aspect ratio of 16:9. PAL is used in most of Europe (except France). If you want to create a National Television System Committee (NTSC) DVD, which is the North American video standard, replace scale=720:576 with scale=720:480, keyint=15 with keyint=18, and -ofps 25 with -ofps 30000/1001. If you don’t have a wide-screen TV, you should encode your file with an aspect ratio of 4:3 by replacing aspect=16/9 with aspect=4/3.

For more information, check the MPlayer’s man page, which provides detailed explanations about each option used in these commands.

This process should take some time to finish. My 1.5GHz Centrino laptop took about 25 minutes to convert a file with a one-hour runtime that was encoded in XviD.

Creating the DVD structure

Now you can use dvdauthor to create the layout of the DVD from the MPEG-2 file of your video. Although you can pass any options to dvdauthor directly from the command line, it’s easier and more flexible to create an XML file with the appropriate options instead. Open your favorite editor and create a file called dvd.xml with the following contents:

dvd.xml

I split my hour-long video into six 10-minute chapters. Adjust the chapters= option for your video, or remove the option from your XML file if you don’t want chapters.

Type dvdauthor -o dvd -x dvd.xml to create the layout of the DVD; the -o switch defines the output directory, and -x is used for the XML file. This command takes five to 10 minutes, depending on your video size and your CPU speed. Once it completes, you’ll have a directory named dvd with two subdirectories: AUDIO_TS and VIDEO_TS. Before burning the video to a disc, you can check it by running mplayer dvd:// -dvd-device ./dvd.

If the video plays correctly, you can burn it onto a DVD disc with growisofs by running growisofs -dvd-compat -Z /dev/dvdrw -dvd-video ./dvd/. Make sure to replace /dev/dvdrw with the device name of your DVD recorder.

Article is taken from http://applications.linux.com/print.pl?sid=06/04/17/2058219

Aug
31

how to convert YouTube videos to divx or xvid

Filed Under Configurations

cat flv2avi.sh

#!/bin/sh

if [ -z "$1" ]; then
echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
exit 1
fi

# video encoding bit rate
V_BITRATE=1000

while [ "$1" ]; do
case "$1" in
-divx)
MENC_OPTS="-ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoaspect"
;;
-xvid)
MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
;;
*)
if file "$1" | grep -q "Macromedia Flash Video"; then
mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame
-lameopts fast:preset=standard -o
"`basename $1 .flv`.avi"
else
echo "$1 is not Flash Video. Skipping"
fi
;;
esac
shift
done

Article is taken from http://www.linux.com/article.pl?sid=06/08/22/2121258

Aug
29

mondo-archive command

Filed Under Configurations

cat /usr/bin/mondo-backup

rm -rf /opt/mondo/*
mkdir -pv /opt/mondo/images /opt/mondo/tmp /opt/mondo/scratch
/usr/sbin/mondoarchive -O -i -N -g -d /opt/mondo/images -T /opt/mondo/tmp -S /opt/mondo/scratch -E /opt -s 4300m

Aug
28

list of installed software : backup and restore

Filed Under Configurations

Backup list of installed software:

debian based distro:

$ dpkg --get-selections > /backup/installed-software.log

rpm based distro:

$ rpm -qa > /backup/installed-software.log

Restore installed software from backup list:
debian based distro:

# dpkg --set-selections < /backup/installed-software.log

# dselect

select “i” for install the software

rpm based distro:

# yum -y install $(cat /backup/installed-software.log)or

# up2date -i $(cat /backup/installed-software.log)

Aug
28

my snmpd.conf

Filed Under Configurations

$ cat /etc/snmpd.conf

com2sec  local               localhost               public
com2sec  network_1      172.31.5.0/24       public

group    MyROGroup           v1               local
group    MyROGroup           v1              network_1
view all-mibs         included   .1           80

access  MyROGroup  “”       v1       noauth    0      all-mibs none   none

syslocation NOC
syscontact vibranze@vibranze.com

Aug
28

install wine from source

Filed Under Configurations

Obtain Wine from http://sourceforge.net/project/showfiles.php?group_id=6241&package_id=77449
tar jxpf wine-0.9.20.tar.bz2
cd wine-0.9.20
./configure –prefix=/usr –bindir=/usr/bin –sbindir=/usr/sbin –mandir=/usr/share/man
make depend
make
make install
winecfg
wine winapps.exe

Aug
28

motion’s config file

Filed Under Configurations

[nlshlt@pclinuxos .motion]$ cat motion.conf
daemon on
quiet on
webcam_port 8000
webcam_localhost off
snapshot_interval 1
snapshot_filename snapshot
locate on
width 320
height 240
framerate 25
quality 85
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0
threshold_tune off
threshold 2000
ffmpeg_cap_new on
gap 10
webcam_quality 50
webcam_maxrate 8
control_port 8080
control_localhost off
control_html_output on
control_authentication user:password
target_dir /home/nlshlt/.motion/
#execute /home/hanlin/.motion/on_motion_detected

Aug
28

convert jpeg to avi using mencoder

Filed Under Configurations

mencoder “mf://*.jpg” -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800