scripts

warning: Creating default object from empty value in /data/web/1/000/027/003/273448/htdocs/panticz.de/modules/taxonomy/taxonomy.pages.inc on line 33.

Autostart script from USB device with Udev

Stage 1: Create Udev rule
sudo wget http://dl.panticz.de/udev/autorun/70-persistent-usb_autorun.rules -O /etc/udev/rules.d/70-persistent-usb_autorun.rules

SUBSYSTEM=="block", KERNEL=="sd*1", ACTION=="add", RUN="/usr/sbin/usb_autorun.sh %E{ID_FS_LABEL} %E{ID_FS_UUID}"

Stage 2: Create autorun wrapper
sudo wget http://dl.panticz.de/udev/autorun/usb_autorun.sh -O /usr/sbin/usb_autorun.sh
sudo chmod a+x /usr/sbin/usb_autorun.sh

#!/bin/bash

SCRIPT=autorun.sh

autorun() {
    if [ -z ${1} ]; then
        FILE=/media/${2}/${SCRIPT}
    else
        FILE=/media/${1}/${SCRIPT}
    fi

    sleep 10

    if [ -f ${FILE} ]; then
        /bin/bash ${FILE}
    fi
}

autorun $@ &

Stage 3: Create autorun.sh script on your USB device (example)
cd /media/YOUR_USB_DEVICE
wget http://dl.panticz.de/udev/autorun/autorun.sh -O ./autorun.sh
chmod a+x ./autorun.sh

#!/bin/bash

USER=$(who | cut -d" " -f1 | head -1)
MAILTO="YOU@YOUR_DOMAIN.COM"

LOG="${0%/*}/backup.$(date -I).log"
CMD="/bin/bash ${0%/*}/backup.sh | tee -a ${LOG}"

if [ -f /home/"${USER}"/.Xauthority ]; then
    # try to open xterm
    export XAUTHORITY=/home/${USER}/.Xauthority
    export DISPLAY=:0.0

    notify-send -i drive-harddisk-usb "Backup" "USB backup started"

    xterm -e ${CMD}

    notify-send -i dialog-ok "Backup" "USB backup completed"
else
    # no X11, run on console
    ${CMD}
fi

# send log by email if sendmail available
if [ -x /usr/sbin/sendmail -a -n "${MAILTO}" ]; then
    # change user for nullmailer
    NULLMAILER_USER=info

    echo "Subject: Backup Log from ${HOSTNAME}" | cat - ${LOG} | sendmail ${MAILTO} 
fi

syncTs.sh

#!/bin/bash
 
EXCLUDES="--exclude=pxelinux.cfg/default --exclude=settings.* --exclude=t5 --exclude=t6 --exclude=t7 --exclude=hwprofile/aktuellesprofil --exclude=sn"
 
for IP in {31..33}; do
	echo $IP
	for DIR in www scripts tftpboot number; do 
		rsync -av ${EXCLUDES} /media/${DIR}/ root@192.168.1.${IP}:/media/${DIR}/
	done
done

Automatically move photos from memory card to hard drive with udev

# create udev rule
cat <<EOF> /etc/udev/rules.d/70-persistent-dcim.rules
KERNEL=="sd*1",SUBSYSTEM=="block",ATTR{partition}=="1",ACTION=="add",RUN+="/usr/sbin/mvdcim.sh \$KERNEL"
EOF
 
# create mvdcim.sh script
cat <<EOF> /usr/sbin/mvdcim.sh  
#!/bin/bash
 
DEVICE=/dev/\${1}
SOURCE=/mnt/DCIM/100NIKON
TARGET=/home/hafr/dcim
 
mount \${DEVICE} /mnt
if [ -d \${SOURCE} ]; then
        mv \${SOURCE}/*.jpg \${TARGET}         
        chmod 666 \${TARGET}/*.jpg
        eject \${DEVICE}
else
        umount /mnt
fi
EOF
chmod +x /usr/sbin/mvdcim.sh
 
 
# monitor changes (optional)
ud

mkEbook.sh

#!/bin/bash
 
# check parameter
if [ $# -lt 1 ]; then
	echo "USAGE: $0 LIST_NO"
	exit
else
	LISTID=$1
fi
 
 
function create_pdfmark() {
cat <<EOF> /tmp/pdfmarks
[ /Author (panticz.de)
/Creator (panticz.de)
/Producer (panticz.de)
/Keywords ($1, panticz.de)
/Title (panticz.de ${LISTID} - $1)
/Subject (panticz.de ${LISTID})
/DOCINFO pdfmark
EOF
}
 
 
for DIR in *
do	
	if [ -d "${DIR}" ]; then
		# convert to lowercase
		OUT=$(echo ${DIR} | tr "[:upper:]" "[:lower:]")
 
		# filter	
		OUT="${OUT// /_}"	# replace " " with "_"
		OUT="${OUT//ä/ae}"	# replace "ä" with "ae"
 

getUniqueFirstLetter.sh

#!/bin/bash
 
FILE=/tmp.$$.out
 
for i in $(ls); do
	echo ${i:0:1} >> ${FILE} 
done
 
cat ${FILE} | sort | uniq
rm ${FILE}
Syndicate content