Jan 6 2013

backup via bash


#!/bin/bash
SERVER="192.168.0.142"
#nice -n 20 dd if=/dev/mmcblk0p1 of=/media/iomega/sheeva_sicherung/mmcblockp1_`date +%d-%m-%Y` bs=1M count=16K
cd /

echo -e "checking if server is mounted... \033[60G [ \033[1;32m`date` \033[0;37m ]"
mount_chk=`cat /proc/mounts | grep cifs| grep $SERVER|cut -f3 -d"/"`

if [ $mount_chk!=$SERVER ]; then
echo "no mount, Please mount manually "
dte="Y";
read -p "shall we mount it? Y/N [Y]" te;
te=${te:-$dte};
if [ $te = "Y" ]; then
echo -e "mount //192.168.0.142/videos /media/iomega/ -o user=0,noatime \033[60G [ \033[1;32mdone \033[0;37m ]"
mount //192.168.0.142/videos /media/iomega/ -o user=0,noatime || (echo "trying to mount... wait 7 sec"; ssh root@192.168.0.142 "/etc/init.d/samba start" );
sleep 6
mount //192.168.0.142/videos /media/iomega/ -o user=0,noatime || (echo "hat net geklappt, exiting...";exit );

else
echo "exiting..."
exit
fi
fi

nice -n 20 echo -e "starting backup... \033[60G [ \033[1;32m`date` \033[0;37m ]"
if [ -f /tmp/file_list ]; then
echo "datei /tmp/file_list existiert... löschen oder benutzen ? ich lösch ma"
dte="Y";
read -p "shall I delete that file? Y/N [Y]" te;
te=${te:-$dte};
if [ $te = "Y" ]; then
rm /tmp/file_list
else
echo "ok, using the existing file then..."
fi
fi

find /bin /boot /dev /etc /home /lib /lost+found /mnt /opt /root /sbin /usr /var > /tmp/file_list

echo -e "file list created, starting cpio... \033[60G [ \033[1;32m`date` \033[0;37m ]"
nice -n 20 cat /tmp/file_list | cpio -o -H newc > /media/iomega/sheeva_sicherung/mmcblockp1_`date +%d-%m-%Y`.cpio.img
#nice -n 20 cat /tmp/file_list | cpio -o -H newc > /media/iomega/sheeva_sicherung/mmcblockp1_`date +%d-%m-%Y`.cpio.gz
#nice -n 20 dd if=/dev/mmcblk0p1 of=/media/iomega/sheeva_sicherung/mmcblockp1_`date +%d-%m-%Y` bs=1M count=16K

echo -e "finish backup... \033[60G [ \033[1;32m`date` \033[0;37m ]"


Aug 12 2012

plist binary file: view or edit without additional software :-)

whenever you install itunes || co, you will have installed al required stuff already. so to view the content of your plist file use following batch file:
you need plutil in the folder %commonprogramfiles(x86)%\Apple\Apple Application Support

then you can also convert back to binary with that tool.
show_plist.bat [plist-file]

cd %commonprogramfiles(x86)%\Apple\Apple Application Support
echo now showing "%1"
echo plutil -convert xml1 -o - "%1"
plutil -convert xml1 -o - "%1"

or to convert them directly:
Bin to XML: plutil -convert xml1 file.plist
XML to Bin: plutil -convert binary1 file.plist


Aug 5 2012

linux server adm – decrease / monitor hd access

first install
apt-get install inotify-tools
maybe also screen to have inotify running with screen in the background

then monitor what is going on. directories after a @ are ignored.

inotifywait -m -r / @/dev @/media @/mnt @/opt @/proc @/root @/sbin @/sys @/tmp @/usr @/bin @/etc @/lib @/var/run/samba/ @/var/cache/samba/

case “$1” in
start)
log_daemon_msg “Starting Samba daemons”
mount -t tmpfs tmpfs /var/run/samba
mount -t tmpfs tmpfs /var/cache/samba

# Make sure we have our PIDDIR, even if it’s on a tmpfs
install -o root -g root -m 755 -d $PIDDIR

at stop)

..
..
fi
fi

umount /var/run/samba
umount /var/cache/samba


log_end_msg 0

;;
reload)

———-
for me it did not do all the trick. samba was still trying to access:
/var/lib/samba so:
mv /var/lib/samba/ /var/lib/samba_
cp -ar /var/lib/samba_ /tmp/samba_lib
ln -sf /tmp/samba_lib /var/lib/samba

(this is what I am currently testing… but should work.. so unconfirmed yet 🙂


Jun 30 2012

bash: if else with floats in bash , for i s, arrays

arr=(“as” “df” 5 kkk “uz z t”);
for ((i=0; i<10; i++));
do echo ${arr[$i]};
done

OUTPUT:

as
df
5
kkk
uz z t

calc if else with floats
a=1.6;b=1.7;if [[ $a < $b ]];then echo $a smaller than $b;fi numbers: i=0 $((i+2)) >> 2


Jun 9 2012

time lapse with ffmpeg

create single images every 25 pic:
ffmpeg -i $1 -r 1 -f image2 out/%05d.png

assemble back all together:
ffmpeg -i out/%05d.png -sameq $2

and as bash script

#!/bin/bash
#create a dir named out by hand, now to lazy
rm out/*
#every 250 /300 one image (10 sec approx)
ffmpeg -i "$1" -r 0.1 -f image2 out/%05d.png
#compile all together with 30fps
ffmpeg -i out/%05d.png -qscale 0 -r 30 "$1.mov"

#this are some useful commands; concate mov's together
echo "mencoder.exe -oac copy -ovc copy -idx -o outall.mov o2.mov o3.mov"

# ffmpeg -i wetter_dortmund.mov -vcodec libx264 -crf 23 -preset medium -profile:v high -level 41 -pix_fmt yuv420p -maxrate 3020k -b 3020k -bufsize 1835k -y fenter_oktay_dortmund.mkv

echo "ls *.mov | while read line;do echo ./timelapse.sh $line;done > st.sh"


Jun 9 2012

rename 00123.png to 00001.png

a=0;ls | while read line; do a=$((a+1)); mv $line `printf “%05d.png\n” $a`;done


Jun 7 2012

multiple VOB file with multiple audio channels

multiple VOB file with multiple audio tracks into avi
we want to have only VOB 4 to 7

for i in `seq 4 7`; do c=`ls VTS_0$i*| grep VOB| grep -v _0.VOB | tr “\n” ” “`;cat $c > $i.VOB;done

for i in `seq 4 7`;do ffmpeg -i $i.VOB -vcodec libxvid -y -acodec libmp3lame -ac 2 -map 0:0 -map 0:2 -map 0:1 -vb 2M -ar 44100 -ab 128 $i.avi;done


May 18 2012

font’s in xterm

xterm -fn 9×15
list of fonts available :  xlsfonts

letters belonging to a given font: xfd


May 18 2012

mount image file’s partition

fdisk -ul image.img
You must set cylinders.
You can do this from the extra functions menu.
Disk image-sda: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device     Boot Start End      Blocks    Id System
image.img *    63    78140159 39070048+ 7  HPFS/NTFS
Partition 1 has different physical/logical endings:
phys=(1023, 254, 63) logical=(4863, 254, 63)
# mount -o loop,offset='''32256''' -t auto image.img mnt/



JFFS2
-----

#!/bin/bash

if [ $# -eq 0 ]; then
echo $0 JFFS2_IMAGE_FILE
exit
fi

modprobe mtdram total_size=44576 erase_size=128
modprobe mtdblock
dd if="$1" of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 m

———

cat /proc/mtd for information of mtd device

.——————-

unpack: rootfs
cat rootfs.gz | lzma -d | cpio -id -H newc
or
cat rootfs.gz | gunzip -c | cpio -id -H newc

pack:

dd if=/dev/zero of=rootfs1 bs=1k count=8192
mke2fs -q -F -m 0 -i 1024 rootfs1

mkdir -p rfs
sudo mount -t ext2 -o loop rootfs1 rfs
cd rfs
tar –exclude=”*/lib*\.a” –exclude=”*/man/*” –exclude=”*/include/*” -cpf – * | \
sudo tar -C rfs -xf –
// sudo chown -h -R 0:0 rfs

find ./rfs | cpio -o -H newc | gzip -9 > rootfs.gz
sudo umount rfs

//gzip -9 -c rootfs1 > rootfs.gz

better to unpack with
cpio -id --no-absolute-filenames

or you will smash your linux…


May 16 2012

initrd auspacken / einpacken | vmlinuz

auspacken:

gunzip < initrd.img | cpio -i –make-directories

 

einpacken:

find ./ | cpio -H newc -o > initrd.cpio

gzip initrd.cpio

mv initrd.cpio.gz initrd.img

———-

 

 

vmlinuz:

od -t x1 -A d vmlinuz | grep "1f 8b 08" 
0008322 1b 00 1f 8b 08 00 d5 c2
dd bs=1 skip=8324 if=vmlinuz | zcat > vmlinux_extract