You are not logged in.
@doorknob60: Here are some changes:
#!/bin/bash
for i in *.flv; do
name=${i%.flv}
ffmpeg -i "$i" -vcodec copy -acodec copy "${name}-pre.mkv"
mkvmerge -o "flv-backup/${name}.mkv" --aspect-ratio "1:4/3" "${name}-pre.mkv"
rm "${name}-pre.mkv"
done
You could consider using absolute paths so your script can be run from any directory.
Offline
Ok, I think I got a better, more generic version Now it lets you preset the desired aspect ratio, the format of the original files (so it will work with mp4s and most other formats too), and the folder you want to work in. Open to more suggestions if anyone has any.
#!/bin/bash
newaspect="4/3"
origformat="flv"
origfolder="${HOME}/Desktop/pm2/orig"
newfolder="${HOME}/Desktop/pm2"
cd "${origfolder}"
for i in *.${origformat}; do
name=${i%.${origformat}}
ffmpeg -i "${origfolder}/${i}" -vcodec copy -acodec copy "${newfolder}/${name}-tmp.mkv"
mkvmerge -o "${newfolder}/${name}.mkv" --aspect-ratio "1:${newaspect}" "${newfolder}/${name}-tmp.mkv"
rm "${newfolder}/${name}-tmp.mkv"
done
Last edited by doorknob60 (2011-09-07 00:38:19)
Offline
#!/bin/bash
# wrapper for Tarsnap
box="archer"
dir="/home /etc"
# base commands
arc="-c -f $box-$(date +%d%m%y) $dir" # archive
tst="-c -f $box-$(date +%d%m%y) --dry-run -v $dir" # dry run
del="-d -f $box-" # delete archive
ext="-x -f $box-" # extract archive
cat <<EOF
Tarsnap options:
a: archive | Create and upload a new snapshot
d: delete | Delete a snapshot
e: extract | Extract an archive
l: list | List all current snapshots
s: summary | Print a summary
t: test | Dry-run a new snapshot
Default: summary
EOF
read -p "Select your option: " input
# get delete specifics
if [[ "$input" = d* || "$input" = e* ]]; then
while true; do
read -p "Which archive? " archive
# check for an archive number
if [[ "$archive" =~ ^[0-9]+$ ]]; then
[[ "$input" = d* ]] && op="${del}${archive}" || op="${ext}${archive}"
break
else
printf "%s\n\n" "Numbers, please..."
fi
done
else
# check remaining options
case "$input" in
a*) op="${arc}" ;;
t*) op="${tst}" ;;
l*) op="--list-archives" ;;
s*) op="--print-stats" ;;
*) op="--print-stats" ;;
esac
fi
# print dry run details to a file
if [[ "$input" = t* ]]; then
printf "%s\n" "Starting dry run: results saved to tarsnapout.txt"
sudo tarsnap $op 2>tarsnapout.txt
else
# run the options
sudo tarsnap $op
fi
I suspect the logic is slightly tortured, but it seems to work...
Offline
This script detects if the user has been idle for 5 minutes, and if he has, shuts down the monitor COMPLETELY, through ddccontrol (amazing tool btw).
You're probably say, why not just use monitor built-in standby? Well, my monitor is broken, so when it goes to standby colors and sharpness get all screwed up So this is a workaround.
#!/usr/bin/python2
import ctypes
import os
import time
class XScreenSaverInfo( ctypes.Structure):
""" typedef struct { ... } XScreenSaverInfo; """
_fields_ = [('window', ctypes.c_ulong), # screen saver window
('state', ctypes.c_int), # off,on,disabled
('kind', ctypes.c_int), # blanked,internal,external
('since', ctypes.c_ulong), # milliseconds
('idle', ctypes.c_ulong), # milliseconds
('event_mask', ctypes.c_ulong)] # events
def queryIdle(dpy, root, xss):
xss_info = xss.XScreenSaverAllocInfo()
xss.XScreenSaverQueryInfo(dpy, root, xss_info)
return xss_info.contents.idle
def main():
xlib = ctypes.cdll.LoadLibrary('libX11.so')
dpy = xlib.XOpenDisplay(os.environ['DISPLAY'])
root = xlib.XDefaultRootWindow(dpy)
xss = ctypes.cdll.LoadLibrary('libXss.so')
xss.XScreenSaverAllocInfo.restype = ctypes.POINTER(XScreenSaverInfo)
monitorIsOff = False
while True:
idleTime = queryIdle(dpy, root, xss)
# 5 minutes
if ((idleTime > 300000) and not (monitorIsOff)):
os.system("sudo ddccontrol -p -r 0xe1 -w 0")
print "Monitor is off."
monitorIsOff = True
if ((idleTime < 10000) and (monitorIsOff)):
print "Idle broken. Assuming monitor on."
monitorIsOff = False
print "Idle time in milliseconds: %d" % idleTime
time.sleep(5)
main()
Last edited by karabaja4 (2011-09-16 22:42:57)
Offline
This small script sets random wallpaper. I use it with hotkey.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import random
WPDIR="/home/zengeist/Images/Wallpapers/"
item = random.choice(os.listdir(WPDIR))
cmd = "pcmanfm -w "+WPDIR+item
os.system(cmd)
exit()
Offline
This small script sets random wallpaper. I use it with hotkey.
#!/usr/bin/python # -*- coding: utf-8 -*- import os import random WPDIR="/home/zengeist/Images/Wallpapers/" item = random.choice(os.listdir(WPDIR)) cmd = "pcmanfm -w "+WPDIR+item os.system(cmd) exit()
find /home/karol/pics -type f | shuf -n1
picks a random file from the specified dir.
Offline
decay_of_mind wrote:This small script sets random wallpaper. I use it with hotkey.
#!/usr/bin/python # -*- coding: utf-8 -*- import os import random WPDIR="/home/zengeist/Images/Wallpapers/" item = random.choice(os.listdir(WPDIR)) cmd = "pcmanfm -w "+WPDIR+item os.system(cmd) exit()
find /home/karol/pics -type f | shuf -n1
picks a random file from the specified dir.
Thx. Now it becomes much simpler and faster.
Offline
I find that ompload ruby script in AUR doesn't work for me anymore. So I made up one in bash.
#!/bin/bash ###:: ompload bash version # TODO: Add 'slow down, cowboy' sleeps URL='http://omploader.org/' TMP='/tmp/ompload.tmp' Q='-#' ; U=0 ; F='OmPlOrD' while getopts 'quf:h' opt ; do case $opt in q) Q='-s' ;; u) Q='-s' ; U=1 ;; f) F="$OPTARG" ;; h) echo '-q for quiet; -u for url only; -f for stdin.name' ; exit 0 ;; esac done shift $((OPTIND-1)) if [ ${#@} -eq 0 ] ; then curl $Q -F "file1=@-;filename=${F}" ${URL}upload -o "${TMP}" URI=$(grep '<!-- View file' "${TMP}" | grep -m1 -o ${URL}'[[:alnum:]]*') echo "${URI}" else for IMG ; do curl $Q -F "file1=@${IMG}" ${URL}upload -o "${TMP}" URI=$(grep '<!-- View file' "${TMP}" | grep -m1 -o ${URL}'[[:alnum:]]*') [ $U == 0 ] && echo "${IMG}" '-->' "${URI}" || echo "${URI}" done fi
Can somebody tell me why the good old ompload ruby script doesn't work anymore? I think it's 'coz the ruby version bump... How do I fix it?
Edit: So I updated the script as Daenyth suggested, allowing stdin as input.
Rats, doesn't work anymore . Any ideas on how to fix?
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Rats, doesn't work anymore . Any ideas on how to fix?
Got it fixed for you... http://ompldr.org/vYW96Nw
This silver ladybug at line 28...
Offline
Gen2ly wrote:Rats, doesn't work anymore . Any ideas on how to fix?
Got it fixed for you... http://ompldr.org/vYW96Nw
Danke. Thanks lolilolicon.
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Something similar has probably been done before, but last night I made a script to manage a todo list with the help of dmenu:
#!/bin/bash
#
# todo: Manages a todo list with the help of dmenu
#
TODOFILE=${HOME}/sandbox/todo
DMENUOPTS="-fn 9x15 -nb #000000 -nf #999999 -sb #333333 -sf #FFFFFF"
MAXLINES=5
touch "${TODOFILE}"
[[ -f "${TODOFILE}" ]] || exit 1
LINECOUNT=$(wc -l "${TODOFILE}" | cut -f1 -d' ')
[[ ${LINECOUNT} -gt ${MAXLINES} ]] && LINECOUNT=${MAXLINES}
INPUT="$(cat "${TODOFILE}" | dmenu -l ${LINECOUNT} ${DMENUOPTS})"
[[ "${INPUT}" ]] || exit 0
if grep -Fx "${INPUT}" "${TODOFILE}" >/dev/null; then
INPUT=$(echo "${INPUT}" | sed 's/\(\*\|\.\|\/\|\[\|\\\|\]\)/\\&/g')
sed -i "/^${INPUT}$/d" "${TODOFILE}"
else
echo "${INPUT}" >>"${TODOFILE}"
fi
exit 0
A YouTube video of the script in use.
Edit: Corrected some bugs, uploaded a better video demonstration.
Last edited by Lars Stokholm (2011-11-26 10:45:16)
Offline
Recently I have been trying out (and liking) openbox more and more. But, the ipblock gui makes it crash for some reason. I read a couple of places it may be java related and I did not see any fix so I wrote this simple bash command line program (needs to be run as root or sudo):
#!/bin/bash
trap 'ipblock -d' 0
ipblock -s
tail -Fq /tmp/ipblock.log 2>/dev/null
exit
It loads your ipblock lists and starts blocking. Then there is an autoscroll for the blocked ips (tail -Fq). When you control+c to leave it turns ipblock back off.
Offline
A simple bash mail notifier for Mutt (Maildir).
Could be also used with conky.
#!/bin/bash
##############
#Mutt notifier
##############
cd ~/Mail/Mutt
orange_new=`du -a -h Orange/ | grep new | grep .arch | wc -l`
if [ $orange_new -gt 1 ]
then
echo "Orange: "$orange_new" new messages"
else
echo "Orange: "$orange_new" new message"
fi
exit 0
EDIT:
Without the `du` command
orange_new=`find Orange/ -name "*.arch" | grep new | wc -l`
Last edited by vcottineau (2011-10-17 09:39:49)
Offline
A simple bash mail notifier for Mutt (Maildir).
Could be also used with conky.#!/bin/bash ############## #Mutt notifier ############## cd ~/Mail/Mutt orange_new=`du -a -h Orange/ | grep new | grep .arch | wc -l` if [ $orange_new -gt 1 ] then echo "Orange: "$orange_new" new messages" else echo "Orange: "$orange_new" new message" fi exit 0
For God's sake, at least use `find' and don't abuse `du'... Right tool for the right job, man.
This silver ladybug at line 28...
Offline
or just glob it since you don't care about anything but the presence of files. This has FAQ 4 written all over it.
#!/bin/bash
shopt -s nullglob
maildir=$HOME/var/mail/gmail
msgs=("$maildir"/*/new/*)
if (( ${#msgs[*]} )); then
printf '%s new messages\n' ${#msgs[*]}
fi
Offline
hello people here's mine, a simple script to install packages from an external list with pacman (the list must be created with the command pacman -Q > ~/list for expamble)
#!/bin/bash
#pacinba=pacman install batch
#es un script que toma desde un archivo que le indicamos como parámetro
#la lista de paquetes ahí contenidos y los instala de forma automática
#para que el script funcione de forma correcta el archivo a leer debe ser
#creado con el comando pacman -Q > archivo (el nombre puede ser cualquiera)
#v1.0 by engelus (@_engelus) bajo licencia GPL v2 o superior
#comprobamos que se hallan pasado los parámetros necesarios
if [ $# -lt 1 ]; then
echo "Se usa de la siguiente forma: pacinba.sh archivo_a_leer"
echo "ej: pacinba.sh ~/.lista"
exit 1
fi
dim=0 #contendra la cantidad de paquetes a instalar
#leemos el archivo linea a linea
while read line
do
#quitamos el nro de versión ya que el comando pacman -Q los almacena en la forma paquete X.X.X-X
paquete="${line% [^ ]*}"
#definimos un array para luego instalar todo con pacman -S
paquetes[dim]=$paquete
((++dim))
done < $1
i=0
sudo pacman -Sy
while ((i <= dim -1))
do
#echo ${paquetes[$i]}
sudo pacman -S ${paquetes[$i]} --noconfirm
((++i))
done
exit
Last edited by engelus (2011-10-21 14:28:40)
Offline
@engelus
Why do you need a script to do it? pacman can
pacman -S - <filelist
This list should be created with the '--quiet' switch so that you get only package names w/o versions:
pacman -Qq > filelist
(this doesn't take into account foreign packages - see wiki: https://wiki.archlinux.org/index.php/Pa … d_packages )
Last edited by karol (2011-10-21 14:34:54)
Offline
@engelus
Why do you need a script to do it? pacman canpacman -S - <filelist
This list should be created with the '--quiet' switch so that you get only package names w/o versions:
pacman -Qq > filelist
(this doesn't take into account foreign packages - see wiki: https://wiki.archlinux.org/index.php/Pa … d_packages )
it's to make same installations in diferents pcs for example or to make a whole reinstalation of the entire system.
I swear I read the wiki looking for that particular command and I could not find it. That was the reason to make the script. Now i am making some alias for those commands you told me
Offline
Wouldn't this be best,
pacman -Qqe > filelist
for packages installed explicitly?
Offline
Wouldn't this be best,
pacman -Qqe > filelist
for packages installed explicitly?
What about AUR packages installed as a dep for another AUR package?
@engelus
Some changes have been made recently (yesterday) to that wiki page https://wiki.archlinux.org/index.php?ti … did=166129 so that's why you might have missed it.
Offline
@karol - aurget has a '--deps' option or in aurgetrc one can set 'resolve_dependencies=true'
Last edited by steve___ (2011-10-21 14:57:09)
Offline
@karol - aurget has a '--deps' option or in aurgetrc one can set 'resolve_dependencies=true'
Of course, if we're not talking about pure pacman then it might be OK, but it depends on the AUR helper.
Offline
I have a script that I could not solve. Is to extract a file and create the folder if it does not exist due a bug in xarchiver, when you try to extract to a non existing forlder it returns an error.The script is basesd in the function posted in the Bash article in the Wiki. The problem is when the file has is some blank spaces in the name, does not work, is there any way to go through the string with the name of the file and add the "\" to make it work.
The script is:
#script para extraer los archivos comprimidos creando el directorio si
#este no existe hasta que se solucione el bug de xarchiver (http://sourceforge.net/tracker/?func=detail&aid=3399118&group_id=140153&atid=745600)
#este scritp esta pensado para usarse como acción acción personalizada de thunar
#por lo que el primer parámtro corresponde al path del archivo seleccionado $1 (%f en thunar)
#el segundo parámtro corresponde al nombre del archivo seleccionado $2 (%n en thunar)
#fuentes consultas wiki de ArchLinux
#v1.0 by engelus (@_engelus)
#!/bin/bash
#comprobamos que se hallan pasado los parámetros necesarios
if [ $# -lt 2 ]; then
echo "Se usa de la siguiente forma: extraer.sh path_del_archivo_a_extrar nombre_archivo_a_extraer"
echo "formatos soportados 7z,Z,bz2,gz,rar,xz,zip,tar"
echo "ej: extraer.sh ~ archivo.zip"
exit 1
fi
NombreSolo="${2%.[^.]*}" #almacenamos el nombre solamente para usarlo luego
#si no existe el directorio donde vamos a extraer lo creamos (es el objetivo de este srcipt :p )
if [ !'test -d '$1'/'$NombreSolo'' ]; then
mkdir -p ''$1'/'$NombreSolo''
fi
c='' #va a almacenar el comando de extracción
#chequeamos la extensicón del archivo y almacenamos en c el comando a usar para descomprimir
case $2 in
*.7z) c='7z x';;
*.Z) c='uncompress';;
*.bz2) c='bunzip2';;
*.gz) c='gunzip';;
*.rar) c="unrar x";;
*.xz) c='unxz';;
*.zip) c="unzip -d";;
*) echo "$0: extensión de archivo no reconocida: '$2'" >&2
esac
#ejecutamos el comando para la extracción del archivo
command $c "$1/$2"
exit
Last edited by engelus (2011-10-21 15:07:12)
Offline
Your quoting (and syntax) is problematic, which is what leads to the issues with spaces in filenames.
if [ !'test -d '$1'/'$NombreSolo'' ]; then
mkdir -p ''$1'/'$NombreSolo''
fi
the square braces are not part of if's syntax. if expects commands, and [ is a command. Additionally, I'm not sure why you're quoting everything except the parts that actually matter.
if [[ -d $1/$NombreSolo ]]; then
mkdir -p "$1/$NombreSolo"
fi
Other things to point out:
1) Your shebang is useless if it isn't on the first line. What you have after the initial comment block is another header. That's it.
2) exit at the end of a script is redundant. It'll exit without that and even pass along the right return value (the exit value of the last run command).
3) commands shouldn't be stored in variables. Use an array and quote it properly on expansion: "${c[@]}"
Offline
Thanks for the answer falconindy the quoting is in that way beacuse i took it from an example, i adapted to fit my script.
If not tell me what the shebang would not have noticed, if you look at my other script is in the right place: p
perhaps, but I read that the "right" to terminate a script was always putting an exit at the end
with respect to expansions do not quite understand yet, but I'm following this tutorial on bash scripting
Offline