You are not logged in.

#1676 2012-01-21 20:48:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

core, extra & community are at 100% :-)
(at least for the 32-bit)

Last edited by karol (2012-01-21 20:50:23)

Offline

#1677 2012-01-21 21:23:13

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

typo. There wouldn't be any reason that a 32 bit package would be signed without the 64 bit complement being signed.

$ signed community
Yes: 1192 [51%]
No: 1136
$ signed extra
Yes: 2047 [73%]
No: 744

Last edited by falconindy (2012-01-21 21:23:46)

Offline

#1678 2012-01-21 21:46:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

The whole [core], 3/4 [extra] and half of the [community] repo is signed.

Very nice script, thank you.

Offline

#1679 2012-01-21 23:20:36

Paulloz
Member
From: Paris, France
Registered: 2012-01-21
Posts: 6
Website

Re: Post your handy self made command line utilities

There might be a cleanest way to do this but it works.
The script extracts archives (extracts it in a sub-folder if it's a tar/rar bomb)

  for file in $@ ; do
    if [ -f $file ] ; then
      tempdir=$(echo $file | sed 's/\..\{3\}$//')
      mkdir -p "$tempdir"
      cp "$file" "$tempdir"
      cd "$tempdir"
      case "$file" in
        *.zip)              unzip       $file;;
        *.tar)              tar xvf     $file;;
        *.tar.bz2 | *.tbz2) tar xjvf    $file;;
        *.tar.gz | *.tgz)   tar xzvf    $file;;
        *.bz2)              bunzip2     $file;;
        *.rar)              unrar x     $file;;
        *.gz)               gunzip      $file;;
        *.Z)                uncompress  $file;;
        *.7z)               7z x        $file;;
        *.xz)               tar xJvf    $file;;
        *)                  echo ""$file" cannot be extracted" >> /dev/stderr;;
      esac
      rm -f $file
      filecount=$(($(ls -l | wc -l) - 1))
      if [ $filecount -lt 2 ] ; then
        for f in * ; do
          mv "$f" "../"
        done
      fi
      cd "../"
      if [ $filecount -lt 2 ] ; then
        rmdir "$tempdir"
      fi
    else
      echo "$file : file not found." >> /dev/stderr
    fi
  done

Why choose the lesser evil ?
You can follow me on Twitter (beware, it's mostly french).

Offline

#1680 2012-01-21 23:26:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Scared of tar bombs? Try atool :-)

Offline

#1681 2012-01-22 11:00:45

Doomcide
Member
Registered: 2011-08-22
Posts: 221

Re: Post your handy self made command line utilities

Here's a little script to pull the newest updates for all git/svn directories in a directory (e.g.: $HOME/src) Shouldn't be too hard to integrate mercurial, too. 

#!/bin/bash

SRCDIR=$HOME/src

cd $SRCDIR
REPODIRS=( */ );

echo ":: Starting source update..."
for DIR in ${REPODIRS[@]}; do
	if [ -d $SRCDIR/$DIR/.git ]; then
		echo ">  $(echo Updating $DIR| sed s'/\///')"
		cd $SRCDIR/$DIR; git pull
	elif [ -d $SRCDIR/$DIR/.svn ]; then
		echo ">  $(echo Updating $DIR| sed s'/\///')"
		cd $SRCDIR/$DIR; svn up
	fi
done
exit

Offline

#1682 2012-01-22 12:18:23

Roken
Member
From: South Wales, UK
Registered: 2012-01-16
Posts: 1,251

Re: Post your handy self made command line utilities

Nice thread, think I'll join in:

This uses gcalcli to extract and format forthcoming appointments from google-calendars. Takes either a an argument for the calendar or reads from a config file. Output is formatted for conky, but could be easily modifed.

#!/bin/bash

# We need linebreaks fixing for the return output from gcalcli
IFS="
"

#Now set up some initial variables

month=`date +%m`
today=`date +%d/%m/%Y`
year=`date +%Y`
thisday=`date +%d`
nmonth=$month
reallytoday=$thisday

# And and array with the number of days in each month
declare -a mlength=( 31 28 31 30 31 30 31 31 30 31 30 31 )

syear=$year
curyear=$year
days=${mlength[$month-1]}
maxdays=$days
let "maxdays = $maxdays + 1"

# Now this bit gets complicated. The script will display the past five days and the next 23 days appointments (28 days in total) so we need some jigarry pokery to fix up the start and end dates
if [ $thisday -lt 6 ]; then
  if [ $month -gt 1 ]; then
    let "month = $month - 1"
  else
    month=12
    let "syear = $year - 1"
  fi
  let "ldays = 5 - $thisday"
  mdays=${mlength[$month-1]}
else
  let "ldays = $thisday - 5"
  let "mdays = $ldays + $ldays"
fi

let "thisday = $mdays - $ldays"

stdate=$month/$thisday/$syear
nday=`expr $days - $reallytoday`
nyear=$curyear

if [ $nday -lt 28 ]; then
  let "nday = 28 - $nday"
  let "nmonth = $nmonth + 1"
  if [ $nmonth -gt 12 ]; then
    nmonth=1
    let "nyear = $curyear + 1"
  fi
fi  
ndate=$nmonth/$nday/$nyear

# OK - we have the date range. The script will work either using a config file for multiple accounts, or by specifying the accoutn details on the script command line, so we need to check both

if [ -f ~/.gcals -a $# = 0 ]; then
  while read line
  do
    # parse the config file
    l=$line
    account=`echo $l | sed 's/user\=\(.*\)password.*/\1/'`
    password=`echo $l |sed 's/.*password\=\(.*\)/\1/'`
    # and get the info from gcalcli
    events=(`gcalcli --user $account --pw $password --nc  --24hr agenda "$stdate" "$ndate"`)
    # Now we need to format it for conky. You must have the colors defined in your conkyrc. Feel free to change the color declarations (or remove them altogether) but make sure you only change or remove \{colorX} or you'll break the sed expressions.
    for i in "${events[@]}"
      do
      ev=""
      ev="$ev`echo $i | sed 's/ \{9\}/\$\{color8\}\$\{goto 130\}/' | sed 's/\( [0-9]\{2\}\)  /\1\$\{color7\}\$\{goto 80\}/' | sed 's/\(:[0-9]\{2\}\)  /\1\$\{color8\}\$\{goto 130\}/'`"
      ev="\${color5}$ev"
      if [ -n $ev ]; then
        echo -e "$ev"
      fi
      done
  done < ~/.gcals
else
    if [ $# = 2 ]; then
    # As above
    events=(`gcalcli --user $1 --pw $2 --nc  --24hr agenda "$stdate" "$ndate"`)
    for i in "${events[@]}"
      do
      ev=""
      ev="$ev`echo $i | sed 's/ \{9\}/\$\{color8\}\$\{goto 130\}/' | sed 's/\( [0-9]\{2\}\)  /\1\$\{color7\}\$\{goto 80\}/' | sed 's/\(:[0-9]\{2\}\)  /\1\$\{color8\}\$\{goto 130\}/'`"
      ev="\${color5}$ev"
      if [ -n $ev ]; then
        echo -e "$ev"
      fi
    done
  else
    # Very limited checking - if there's no config file and less than two command line arguments, output an error
    echo "Not enough arguments"
  fi
fi

And I've added this to rc.local.shutdown, but could just as easily be used standalone, to unmount mounts in /media and mnt/ (I did this because if I failed to unmount local mounts the kernel complained on the next boot)

#!/bin/bash

STIFS=$IFS
IFS='
'
mounts=(`mount | grep media`)
points=${#mounts[*]}
for ((i=0; i<$points; i++))
do
	mpoint=`echo "${mounts[$i]}" | sed 's/\ .*//'`
	echo "Unmounting: $mpoint"
	umount $mpoint 
done
mounts=(`mount | grep mnt`)
points=${#mounts[*]}
for ((i=0; i<$points; i++))
do
	mpoint=`echo "${mounts[$i]}" | sed 's/\ .*//'`
	echo "Unmounting: $mpoint"
	umount $mpoint 
done
IFS=$STIFS

This will take a random picture from a pre-defined folder and resize it, ideal for conky, picframe screenlet etc. Takes a 3 line config with the folder name, the time between changes (in seconds) and the size of the end picture (e.g. 160x120)

#!/bin/bash
# Have the script recognise spaces in directory paths and filenames
IFS='
'
#Now we need to check if the script is already running. For some odd reason it seems to survive after a relog
PDIR=${0%`basename $0`}
LCK_FILE=~/.`basename $0`.lck
trap 'rm ${LCK_FILE};exit' 1 2 3 15
if [ -f "${LCK_FILE}" ]; then
	MYPID=`head -n 1 "${LCK_FILE}"`
	TEST_RUNNING=`ps -p ${MYPID} | grep ${MYPID}`

	if [ -z "${TEST_RUNNING}" ]; then
		# It's not running, let's signal that
		echo $$ > "${LCK_FILE}"
	else
		# An instance is already running. Exit gracefully
		echo "Randompic is already running"
		exit 0
	fi
else
	echo $$ > "${LCK_FILE}"
fi

#This is the main bit

while :
do
	# Read the config file
	exec 3<> ~/.conkypic
	read <&3 dirpath
	read <&3 timeout
	read <&3 as
	exec 3>&-
	# Now get a list of files
	cd $dirpath
	files=(`ls -1 *.[Jj]??`)
	len=${#files[*]}
	if [ "$len" != "0" ]; then
		# Pick a file at random
		number=$RANDOM
		let "number %= $len"
		# Now we copy it a temporary location. The following copies to RAM. If you are short
		# on memory change the location to somewhere in /home
		cp "${wd}${files[$number]}" /dev/shm/conkypic.jpg
		# Convert the image for conky
		mogrify -format png -resize $as /dev/shm/*.jpg &
	fi
	# Wait before rep[eating
	sleep $timeout
done

Last edited by Roken (2012-01-22 12:20:47)


Ryzen 5900X 12 core/24 thread - RTX 3090 FE 24 Gb, Asus Prime B450 Plus, 32Gb Corsair DDR4, Cooler Master N300 chassis, 5 HD (1 NvME PCI, 4SSD) + 1 x optical.
Linux user #545703

Offline

#1683 2012-01-24 04:00:10

evil
Member
From: Indianapolis, IN
Registered: 2010-03-06
Posts: 41
Website

Re: Post your handy self made command line utilities

Here is one that I wrote a long time ago, have shared here somewhere, but have recently scrapped and re-wrote the entire thing. Basically, it will create blank (or filled via template) script files chmodded executable, to any location you wish. By not specifying a location, it goes in the current working directory.

#!/bin/bash
# makescript - creates an already chmodded script
# Template script from planet.archlinux.org

scrpt=${0##*/}  # script name

# Display usage if no parameters given
if [[ -z "$@" ]]; then
  echo "${scrpt} ran without any options/arguments. Goodbye."
  exit
fi

# Text color variables
txtred='\e[0;31m'       # red
txtgrn='\e[0;32m'       # green
txtylw='\e[0;33m'       # yellow
txtblu='\e[0;34m'       # blue
txtpur='\e[0;35m'       # purple
txtcyn='\e[0;36m'       # cyan
txtwht='\e[0;37m'       # white
bldred='\e[1;31m'       # red    - Bold
bldgrn='\e[1;32m'       # green
bldylw='\e[1;33m'       # yellow
bldblu='\e[1;34m'       # blue
bldpur='\e[1;35m'       # purple
bldcyn='\e[1;36m'       # cyan
bldwht='\e[1;37m'       # white
txtund=$(tput sgr 0 1)  # Underline
txtbld=$(tput bold)     # Bold
txtrst='\e[0m'          # Text reset

# Feedback indicators
info="${bldwht}${scrpt}${txtrst}"
pass="${bldblu}${scrpt}${txtrst}"
warn="${bldred}${scrpt}${txtrst}"

# Constants
shabang='#!'
interp="${shabang}bin/bash"
template=''
ch_interp=''
ch_templ=''
moveto=''

while getopts ":s:t:hm:" FLAG;
	do
		case $FLAG in
			s) 
				ch_interp=$(which ${OPTARG} 2> /dev/null)
				[[ ${ch_interp} != "" ]] && interp="${shabang}${ch_interp}"		;;
			t) 
				ch_templ="$OPTARG"
				[[ -f ${ch_templ} ]] && template='.'							;;
			h) 
				echo -e "Usage: ${info} [options] filename(s)\n\n	-s [interpreter]	Choose script interpreter. Simply type bash for bash.\n	-t [path-to-template]	Use a template. Template should already have shabang.\n	-m [path]		Move script to path."
				exit 0													;;
			m)
				[[ -d "$OPTARG" ]] && moveto="$OPTARG"						;;
			\?) echo -e "${warn}: Invalid option: -$OPTARG"; exit 1				;;
		esac
	done

shift $((OPTIND-1))

for each in "$@";

	do
	
		[[ "$each" == "" ]] && echo -e "${warn}: No filename given." && exit 1
		
		if [[ -f "$each" ]]; then
			read -p "${scrpt}: $each exists. Over-write? (y/n)" ans
			case $ans in
				y | Y) 									;;
				n | N) exit 1								;;
				*) echo -e "${warn}: Invalid Option."; exit 1	;;
			esac
		fi
		
		if [[ ! ${template} == '' ]]; then
			cat ${ch_templ} > "$each"
			chmod +x "$each"
			echo -e "${info}: Created and CHMODed $each with template ${ch_templ}"
			exit 0
		fi

		echo -e "${interp}\n\n" > "$each"
		chmod +x "$each"
		echo -e "${info}: Created and CHMODed $each"
		
		if [[ "${moveto}" != "" ]]; then
			mv "$each" "${moveto}"
			echo -e "${info}: $each moved to ${moveto}"
		fi
		
	done

Site | Blog | Freenode Nick: i686

Offline

#1684 2012-01-24 12:35:21

answer_42
Member
From: Steenbergen, Netherlands
Registered: 2010-06-28
Posts: 8

Re: Post your handy self made command line utilities

A small perl script to download all files of a specific type from a website...

#!/usr/bin/perl
use strict;
use warnings;

use LWP::Simple;

usage() if @ARGV != 2;

my $url  = $ARGV[0];
my $type = $ARGV[1];

my $content = get($url);
unless ($content) {
    die "Something went wrong with downloading the page!.";
}

map { /.*\/(.+)$/; getstore($_, $1) }
    grep { /\.${type}$/ } ($content =~ /href="(.*?)"/g);

sub usage {
    print "Usage: $0 <url> <type>\n";
    print "This program downloads all files from the specified webpage of\n";
    print "the chosen filetype.\n";

    exit(0);
}

__END__

Offline

#1685 2012-01-24 12:40:27

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Is it the ame as e.g. 'wget -A.jpg,gif' ?

Offline

#1686 2012-01-24 13:08:48

answer_42
Member
From: Steenbergen, Netherlands
Registered: 2010-06-28
Posts: 8

Re: Post your handy self made command line utilities

Yeah, similar...didn't know that wget could do this wink

Offline

#1687 2012-01-31 20:12:29

sujoy
Member
From: India
Registered: 2008-02-08
Posts: 94
Website

Re: Post your handy self made command line utilities

This gets the path to the current flash movies playing in youtube so that one can just copy it someplace if required smile

#!/bin/sh

for i in /proc/$(ps ax | awk '/flash/ && !/grep/ {print $1}')/fd/* ;do
 file "$i"
done | awk -F":" '/\/tmp\/Flash/ {print $1}'

Last edited by sujoy (2012-01-31 20:13:04)

Offline

#1688 2012-01-31 20:22:24

saline
Member
Registered: 2010-02-20
Posts: 86

Re: Post your handy self made command line utilities

I had the need to convert some maildir trees to mboxes.

#!/usr/bin/python

import mailbox
import sys

if len(sys.argv) != 3:
    print(sys.argv[0], "<maildir_path> <mbox_path>")
    sys.exit(-1)

maildir = mailbox.Maildir(sys.argv[1], create=False)
mbox = mailbox.mbox(sys.argv[2])

i = 0

for message in maildir:
    mbox.add(message)
    i += 1
    print("\rmessages processed:", i, end='')

print()

Offline

#1689 2012-02-02 09:45:54

noMaster
Member
Registered: 2009-07-05
Posts: 70

Re: Post your handy self made command line utilities

Laptop script changes governor. If soft keys doesnt work:

p2=("ondemand")
p3=("powersave")

### Current cpu governor
she_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`

if   [[ "${she_current}" == "${p1}" ]]; then
		cpufreq-set -c 0 -g ondemand && cpufreq-set -c 1 -g ondemand
elif [[ "${she_current}" == "${p2}" ]]; then
		cpufreq-set -c 0 -g powersave && cpufreq-set -c 1 -g powersave
elif [[ "${she_current}" == "${p3}" ]]; then
		cpufreq-set -c 0 -g performance && cpufreq-set -c 1 -g performance
fi

Offline

#1690 2012-02-02 10:46:13

graph
Member
Registered: 2010-12-21
Posts: 105

Re: Post your handy self made command line utilities

This will mount both encrypted (with dm-crypt/LUKS) and ordinary disks, and, if they are already mounted, unmount them. Got tired of all the encryption-commands needed, and decided to get lazy with some bash.

#!/bin/bash
# mountc: A script for managing encrypted and ordinary disks.

PART=$(basename $1)

# Check for root
if [[ $EUID -ne 0 ]]; 
then # We are not root
	echo "This script must be run as root" 1>&2
	exit 1
fi

# Check for arguments
if [ "x$1" = "x" ];
then
	echo "Usage: $(basename $0) device"
	exit 1
fi

# Set variable if drive is mounted
if [ "$(mount | awk '{ print $1 }' | grep -o $PART)" = "$PART" ];
then
	MOUNTED="yes"
fi

# Check for encryption (via exitcode)
if [ "$(sudo cryptsetup luksDump /dev/$PART 2>&1 > /dev/null && echo $?)" = "0" ]; 
then # LUKS-device
	if [ "$MOUNTED" = "yes" ];
	then # Drive is already mounted, umount it
		umount /dev/mapper/$PART
		cryptsetup luksClose $PART
		echo "Unmounted /dev/$PART."
	else # Drive is NOT mounted, mount it
		cryptsetup luksOpen /dev/$PART $PART
		mkdir -p /media/$PART
		mount /dev/mapper/$PART /media/$PART
	fi
else # Not a LUKS-device (or options given for mount)	
	if [ "$MOUNTED" = "yes" ];
	then # Drive is already mounted, umount it
		umount "$@"
	else # Drive is NOT mountes, mount it
		mount "$@"
	fi
fi

Last edited by graph (2012-02-02 12:02:02)

Offline

#1691 2012-02-03 22:28:13

haiku
Member
From: Chambery, France
Registered: 2011-01-28
Posts: 19

Re: Post your handy self made command line utilities

I've just spend the last three days learning, well, not only bash, but the logic behind scripting...
Why? because I wanted to sort my Pictures according to their orientation...and couldn't find a way to do that.

So, here it is, a script to sort pictures
(it's probably a bit bloated, but it was a good exercice to learn the underlying struture of scripting)

#!/bin/bash

#Give lists of selected pictures, sorted by orientation
#
#!!!!Dependencies: feh ; bc ; bash>4.0


#set current time for output filenaming
currenttime=$(date +%Y-%m-%d-%Hh%M)

function main {
#Ask for file directory path, then call sorting function
	read -e -p "Path to Pictures Directory?" -i "$HOME/" pathtoimage
	if test -d "$pathtoimage"
		then sortpictures
	else echo "Path is not valid"; main
	fi
}

function sortpictures {
#Picture sorting

	function recurs {
	#Ask for recursive sorting
	#feh outputs a path/to/image#width#height formated list

		read -e -p "Include subdirectories? (y/n) " recursivite
		if [[ "$recursivite" = y ]]
			then feh -r -L %f#%w#%h $pathtoimage > /tmp/listemp
		elif [[ "$recursivite" = n ]]
			then feh -L %f#%w#%h $pathtoimage > /tmp/listemp
		else clear; recurs
		fi
	}

	recurs

	while read LINE 
	do 
	#Sorting feh output's fields

		picpath=$(echo $LINE | cut -d"#" -f1)
		picw=$(echo $LINE | cut -d"#" -f2)
		pich=$(echo $LINE | cut -d"#" -f3)
		ratio=$(echo $picw/$pich | bc -l)

	#Compare picture width/height ratio to a somehow arbitrary ratio (yeah, magic number!)
	#and output to a list

		if (( $(bc <<< "$ratio > 1.2") ))
			then echo $picpath >> /$pathtoimage/sortedbylandscape$currenttime
		elif (( $(bc <<< "$ratio < 0.8") ))
			then echo $picpath >> /$pathtoimage/sortedbyportrait$currenttime
		else echo $picpath >> /$pathtoimage/sortedbysquare$currenttime
		fi

	done < /tmp/listemp

	rm /tmp/listemp
	echo "Lists written to $pathtoimage directory"
}

main

Hasta la Singularidad Siempre

Offline

#1692 2012-02-04 03:58:32

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: Post your handy self made command line utilities

Great work there for a first script haiku.  One little bit of streamlining would be to replace

if (( $(bc <<< "$ratio > 1.2") ))

with

if [[ $ratio -gt 1.2 ]] 

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#1693 2012-02-04 04:13:23

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Post your handy self made command line utilities

Trilby wrote:

Great work there for a first script haiku.  One little bit of streamlining would be to replace

if (( $(bc <<< "$ratio > 1.2") ))

with

if [[ $ratio -gt 1.2 ]] 

No. Absolutely not. bash doesn't do floating point arithmetic.

$ ratio=3
$ [[ $ratio -gt 1.2 ]]
bash: [[: 1.2: syntax error: invalid arithmetic operator (error token is ".2")

Regardless, (( )) is the preferred context for arithmetic operations over [[ ]].

Offline

#1694 2012-02-04 11:48:27

haiku
Member
From: Chambery, France
Registered: 2011-01-28
Posts: 19

Re: Post your handy self made command line utilities

Thanks guys - it kinda struck me when I first read that bash couldn't do float arithmetic :-)
About the (( )) syntax, I got to admit I just saw it on the net...

I'll probably work on it some more : my to-do list is to implement positional parameters as an input for the picture folder path (it would be easier to call the script that way from another script), and as an input for a minimum ratio instead of it being hard-coded.
Anyway thanks!

PS Funny how the replies I get are from two people from Massachusetts and New Jersey... and end up disagreeing...on this particular Superbowl Week-end ;-)


Hasta la Singularidad Siempre

Offline

#1695 2012-02-04 14:55:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: Post your handy self made command line utilities

Oops... sorry.  I stand corrected, and more fully educated.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#1696 2012-02-04 15:09:08

majiq
Member
Registered: 2009-03-06
Posts: 259

Re: Post your handy self made command line utilities

Code to watch a file until its size stops changing and then shutdown the machine. It also prints out periodic reminders about the time and filesize.

N.B. It uses a shutdown script.

#!/bin/bash

if [ ! $# -eq 1 ]; then
  echo "Usage: $0 <file>"
  exit 1
fi

if [ ! -e $1 ]; then
  echo "Invalid file"
  exit 2
fi

count=0
old_size=`stat $1 -c "%s"`
while true; do
  sleep 30
  new_size=`stat $1 -c "%s"`
  if [ $new_size -eq $old_size ]; then
    shutdown.sh shutdown
    break
  fi
  let "count += 1"
  let "count %= 10"
  if [ $count -eq 0 ]; then
    date
    echo $1
    echo `ls -sh $1 | cut -f1 -d' '`
    echo
  fi
  old_size=$new_size
done

exit 0

Offline

#1697 2012-02-05 20:00:38

jutnux
Member
Registered: 2012-01-18
Posts: 5

Re: Post your handy self made command line utilities

#!/bin/bash

USER="liam"
SERVER="88.198.223.123"
DIR="~/screenshots"
FILENAME="$(date -d 'today' +%d-%m-%Y-%H.%M)"
SITE="$SERVER/~liam/screenshots/$FILENAME.png"

scrot -e "mv \$f $FILENAME.png"

scp "$FILENAME.png" $SERVER:$DIR

rm "$FILENAME.png"

echo "http://$SITE"

Need something to automate uploads to my server and this 5 minute script makes it pretty easy. Planning to increase what it can do with options to select (basically what scrot does) but uploading it at the same time.

Last edited by jutnux (2012-02-05 20:00:57)

Offline

#1698 2012-02-09 13:46:41

C. M. Harlequin
Member
From: Australia
Registered: 2011-12-23
Posts: 35

Re: Post your handy self made command line utilities

phrakture wrote:
Allan wrote:

Kill gnome-screensaver before starting mplayer

#!/usr/bin/env python 

import os
import os.path
import sys

os.system("killall gnome-screensaver")

command = '/usr/bin/mplayer %s "%s"' % (' '.join(sys.argv[1:-1]), os.path.normpath(sys.argv[-1]))
os.system(command)

os.system("gnome-screensaver")

I still do not understand the "command =" line but it works big_smile

Just an FYI. xscreensaver has a -disable command that disables the screensaver for some time. You can use that with mplayer's "heartbeat-cmd" setting - might be cleaner to do it that way

http://www.xkcd.com/196/


διπλοῦν ὁρῶσιν οἱ μαθόντες γράμματα.

Offline

#1699 2012-02-14 01:25:46

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Post your handy self made command line utilities

This is an attempt to ensure that when I restart X, multiple versions of the same process are not spawned. It works, but it seems needlessly kludgy...

#!/bin/bash
# Check if app is running on starting X

list=(mpd mpdscribble highlights)

for app in "${list[@]}"; do
    check=$(ps -C "$app" -opid=)
    if [[ -z "$check" ]]; then
        case "$app" in
                mpd) mpd $HOME/.mpd/mpd.conf    ;;
        mpdscribble) mpdscribble &              ;;
         highlights) $HOME/Scripts/highlights & ;;
        esac
    fi
done

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#1700 2012-02-14 03:48:29

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Post your handy self made command line utilities

Could do:

pgrep mpd &>/dev/null || mpd $HOME/.mpd/mpd.conf
pgrep mpdscribble &>/dev/null || mpdscribble &
pgrep highlights &>/dev/null || $HOME/Scripts/highlights &

Offline

Board footer

Powered by FluxBB