Main Page‎ > ‎

Misc howto

Misc howto use notes for describing commands that I often use

Download photos from my canon powershot S50

For that purpose I use gphoto2. The Canon S50 talks PTP in a generic fashion but is now natively supported by gphoto2. In order to retreive all the files I use the following command: gphoto2 --camera "Canon PowerShot S50 (normal mode)" --get-all-files 
For using the default PTP mode you can try instead:gphoto2 --camera "USB PTP Class Camera"
In order to retreive a special range of photos:
  • identify the internal numbers associated with the desired photos throughg photo2 --camera "Canon PowerShot S50 (normal mode)" -L 
  • pick the ones (e.g. 47 to 52) gphoto2 --camera "Canon PowerShot S50 (normal mode)" -p 47-52 

Spam immunity: spamassassin

  • create .procmailrc file with the following lines
PATH=/usr/local/bin:/bin:/usr/bin 
SHELL=/bin/sh 
LOGFILE=/dev/null 
SPAMDIR=$HOME/mail/spam 
# perform before all the filtering for mailing lists here 
# only process if message under 250*1024 bytes 
:0fw * < 256000 | spamassassin 
 # reroute tagged as spam emails to your spam mbox 
# if score is higher than 15 it is almost sure that it is a spam 
:0: * ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\* $SPAMDIR/spamassassin-sure 
 # others are probable spams 
:0: * ^X-Spam-Flag: (Yes|YES) $SPAMDIR/spamassassin-pehaps
  • in your .muttrc in order to tag messages as spam use the following macro:
# mark as spam and delete 
macro index S "|sa-learn --spam --no-rebuild --single\n; <delete-message>\n\n" 
macro index S "|sa-learn --spam --no-rebuild --single\n; <delete-message>\n\n" 
# mark as ham and save to some folder
macro pager H "|sa-learn --ham --no-rebuild --single\n; <save-message>\n" 
macro pager H "|sa-learn --ham --no-rebuild --single\n; <save-message>\n" 
# rebuild the spamassassin bayes filter db 
macro index R "!/usr/bin/sa-learn --rebuild"
 
  • to learn from a mailbox use: sa-learn --mbox --spam $SPAMBOX sa-learn --mbox --ham $HAMBOX 
  • use the following user prefs for spamassassin in .spamassassin/user_prefs
required_hits 3.0 
rewrite_subject 0 
whitelist_from "*.courville.org", "*.crm.mot.com", "*.motorola.com", "*.enst.fr" 
# Bloody spammers faking my whitelist!! 
blacklist_fromno from@email.mot.com *@motgate*.mot.com *@ftpbox.mot.com 
skip_rbl_checks 1 
check_mx_attempts 0 
ok_languages fr en 
use_bayes 1 auto_learn 1 
# If Bayesian filter says its spam, I trust it. Up the scores. 
score BAYES_60 0 0 2.000 2.100 
score BAYES_70 0 0 4.000 4.100 
score BAYES_80 0 0 5.300 5.400 
score BAYES_90 0 0 7.000 7.100 
score BAYES_99 0 0 10.200 10.300
 # HABEAS warrants are now useless as spammers are forging them 
score HABEAS_SWE 0
  • save your unfiltered spams into a specific folder e.g.: mail/spam and make spamassassin learn about it through a sa-learn --spam --mbox $HOME/mail/lspam then erase the mailbox.

install full directory content on your palm

I use either jpilot (gui) or directly pilot-link commands: pilot-xfer -p /dev/usb/tts/1 -i *.prc *.pdb 

rebuild index for damaged avi file

  • for single play (no fix): mplayer -idx myvideo.avi
  • fix it: mencoder -oac copy -ovc copy infile.avi -o outfile.avi
  • in case of serious damage use ffmpeg which is more fault tolerant: ffmpeg -i infile.avi -acodec copy -vcodec copy -o outfile.avi
  • save index: mplayer -idx myvideo.avi -saveidx myvideo.idx
  • use saved index: mplayer myvideo.avi -loadidx myvideo.idx

convert your vhs family tapes into divx movies

  • perform acquisition with your happauge PVR250 in mpeg format using 720x576 resolution through a cat /dev/video3 > myvideo.avi. What I did is to use both peritel outputs of my VCR one linked to the PVR250 the other one linked to a standard video card in another PC for monitoring and launching remotely the acquisition. This way you avoid the unavoidable delay introduced by the MPEG coding of the PVR250.
  • get rid of the temp file rm frameno.avi 
  • perform 1st path audio only avi creation mencoder input.mpg -ovc frameno -oac mp3lame -lameopts vbr=3 -o frameno.avi 
  • run 2nd path: actually 1st video path, use as bitrate the mencoder recommendation values for 650/700/800Mb files after previous pass mencoder input.mpg -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=$bitrate -o output.avi 
  • finish by the 3rd path: actually 2nd video path, optionnaly replace as bitrate the mencoder recommendation values for 650/700/800Mb files after previous pass mencoder input.mpg -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=2:vbitrate=$bitrate -o output.avi
  • for an enhanced quality I use the following script:
#!/bin/sh 
filein=$1 
fileout=$2 
sizex=$3 
sizey=$4 
bitrate=$5 
rm -f frameno.avi 
mencoder $filein -ovc frameno -oac mp3lame -lameopts vbr=3 -o frameno.avi 
echo potentially refine bitrate variable based on above inputs 
mencoder $filein -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=$bitrate:vqscale=3:vhq:v4mv:trell -o $fileout -vf scale=$sizex:$sizey -sws 2 
echo potentially refine bitrate variable based on above inputs 
mencoder $filein -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=$bitrate:vqscale=3:vhq:v4mv:trell -o $fileout -vf scale=$sizex:$sizey -sws 2
  • acquisition of dv with sony dvcam, by default do autosplit and include date time in filename dvgrab --format dv2 --autosplit --timestamp aviout- 

Printing with gimp/cups/turboprint

  • configure printer as Postscript level 2
  • select proper media size
  • remove the -oraw option only should remain lp -s -dplume if plume is your target printer

smbclient and french charset

What I use for displaying correctly the filenames (avoiding the alternate command) when using a smbclient: smbclient //windaube/docs -t iso8859-15 

CVS update command

alias cup='cvs -qz3 up -PAd'

burn iso of your favorite distro

cdrecord -v -dao -eject dev=0,0,0 speed=52 driveropts=burnfree fs=4049k timeout=20 -overburn -isosize sarge-i386-netinst.iso

Euro symbol with latex

apt-get install tetex-eurosym 
\usepackage{eurosym} \euro{10.00}

Create your xface

  • get the appropriate software apt-get install xfaces compface 
  • generate a square image with gimp out of your photographic picture 
echo -n "X-Face:" > my_image.face 
convert -despeckle -geometry 48x48 my_image.jpg xbm:- | compface >> my_image.face
  • in order to include the resulting line in your .muttrc use quote-x-face to quote some forbidden characters 
./quote-x-face my_image.face > muttrc.face 
cat quote-x-face 
#!/usr/bin/perl -w 
# perl script to quote my_hdr commands for Mutt. 
# mainly useful for X-Face. headers.
# (c) 2004 Christoph Berg, GNU GPL. 
# 2004-06-13 cb: initial version 
@f = <>; foreach (@f) { chomp; s/(\\;'"`\$#)/\\$1/g; } print "my_hdr "; print join '\n', @f; print "\n";

List open ports

echo "Open Ports:"; netstat -anp | grep LISTEN | grep tcp | awk '{print $4, "\t", $7}' | less

Multimedia file information

Just use mediainfo
List HEVC mkv files that do not have a mp4 counterpart:
find . -print0 -name \*mkv -exec mediainfo --Output=file://./template.txt {} \; | grep HEVC | sed -E 's;(.*)\.mkv HEVC;\1.mp4;g' | xargs -0 ls 2>&1 >/dev/null | sed -E 's;^.*(\./.*mp4).*$;\1;g'
find . -name \*mkv -exec mediainfo --Output=file://./template.txt {} \; | grep HEVC | sed -E 's;(.*)\.mkv HEVC;\1.mp4;g' | while read f; do ls ${f} 2>&1 >/dev/null | sed -E 's;^.*(\./.*mp4).*$;\1;g'; done
cat template.txt
General;%CompleteName% * %FileSize/String3% * %Duration/String%
Video; |Video: %Width%x%Height% * %DisplayAspectRatio/String% * %Format% %Format_Profile%
Audio; |Audio: %Language/String% * %Channel(s)% CH * %Codec/String%
Text; |Sub: %Language/String% * %Codec%
File_End;\n

Count number of unique number of approvals

cat ggapproved.mbox | grep "Final Approval" | sed 's/.* \([^ ]*\)$/\1/g' | sort -f -d -u | sort -u | wc -l
Graph it:
egrep -h "^(Date|.*-keys)" * | sed "s/^Date: //g" | paste -sd'|\n' | while read i;do date -d"$(cut -d '|' -f 1 <<<$i )" +%Y%m%d; cut -d'/' -f 3 <<<$(cut -d '|' -f 2 <<<$i ) | sed 's/:.*$//g' ; done | paste -sd',\n' | awk -F, '!a[$1]++'

Clean inactive mosh sessions

ps h --sort start_time -o pid,command -C mosh-server | head --lines=-1 | awk '{print $1}' | xargs --no-run-if-empty -n 1 --verbose kill

Copy all jpeg files, delete empty dirs and delete duplicates

rsync -r --exclude="thumb/" --exclude="archive/" --exclude="deleted/" --exclude="temp/" --include="*/" --include="*.[Jj][Pp][Gg]" --exclude="*" ./ $HOME/tmp/
cd $HOME/tmp
find . -type d -empty -delete
OUTF=rem-duplicates.sh; echo "#! /bin/sh" > $OUTF; find "$@" -type f -print0 | xargs -0 -n1 md5sum | sort --key=1,32 | uniq -w 32 -d --all-repeated=separate | sed -r 's/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\1/g;s/(.+)/#rm \1/' >> $OUTF; chmod a+x $OUTF; ls -l $OUTF

EOF

Comments