Hardcore Linux

Anything about Ubuntu, Centos, openSuSe and Fedora

Category Archives: script

Autorefresh CUPS printers

This cron script will automatically reactive all disabled CUPS printers. In our office it’s a daily problem when a faulty start or  a minor operational problem might deactivate the  said printer/s. This scripts will help you automatically enable all disabled printer Hope this work 100% for your CUPS configuration.

Updates: fixes the LIST_PRINTERS value.(03/16/2010)

#!/bin/bash
# Re-activate all paused or faulty printers
# by https://hardc0l2e.wordpress.com
#==========================================
LIST_PRINTERS=`lpstat -p | grep printer | grep -v enable | awk '{print $2}' | sed '/^$/d'`
if [ "x$LIST_PRINTERS" !=  "x" ]; then
  for printername in $LIST_PRINTERS; do
    echo "Activating $printername ..."
    cupsenable $printername > /dev/null
  done
fi
sleep 1

Reduce image resolution BASH script

One of my problem in System Administration is auto-converting images to a slight lower resolution when its stored in our File Server, Most of our JPGs are gathered from numbers of digital cameras which they only intend to store in their private network folder. A high resolution image consume too much resources.

I also impost a policy which restrict of storing unrelated documents in our File Server, but still some refuse to abide and still storing images in high resolution. So here’s one of my script that might be useful to you in case we are on same scenario.

#!/bin/bash
# JPGCONVERT
#----------------------------
# by http://twitter.com/c0l2e
#    ronartos@gmail.com
#============================
# converts images with resolution higher than 1024x1024 to lower at least 50% or original

LOCATION=$1
TARGET_FILES=`find "$LOCATION" -iname "*.JPG" | sed 's/ /|/g'`

for files in $TARGET_FILES
  do
       #TESTFILE=`echo "$files" | sed 's/|/ /g' | xargs file -b | awk '{print $1}'`
       TEST1=`echo $files | sed 's/|/ /g'`  #$TESTFILE
       TEST2=`file "$TEST1" -b | awk '{print $1}'`
       if [ "$TEST2" = "JPEG" ]; then
            #echo $TEST1
            OLDEXT="jpg"
            NEWEXT="png"
            find "$TEST1" -iname "*.$OLDEXT" |
            while read F
            do
                 NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
                 #echo "mv \"${F}\" \"${NEWFILE}\""
                 convert "$F" "$NEWFILE"
                 CHECKSIZE=`file "$NEWFILE" -b | sed 's/ //g' | sed 's/,/ /g' | awk  '{print $2}' | sed 's/x/ /g' | awk '{print $1}'`
                 if [ $CHECKSIZE -ge  1024  ]; then
                    convert  "$F" -resize 50% "$F"
                 fi
                 rm "$NEWFILE"
            done
       fi
  done