[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Shell Script General
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 186
Thread images: 9
File: terminal.png (20 KB, 256x256) Image search: [Google]
terminal.png
20 KB, 256x256
Share with us your little scripts which help you improve your live

an alias is fine too

I'll start with three simple ones:

screenshot script:
#!/bin/sh

#take a fullscreen screenshot
#requires: imagemagic
#optionally: optipng

##########configurable##########
##
DATE=`date +%Y-%m-%d_%H:%M:%S`
PLACE=$HOME/Pictures/scrots
##
################################

SCREENS=`xrandr | grep Screen -c`
#the number of connected Monitors

COUNT=0

mkdir -p $PLACE/jpg

while [ $COUNT -lt $SCREENS ]
do
#take screenshots for every monitor, put em in /tmp
#stitch em together and delete the temporary file
import -window root -display :0.$COUNT -screen /tmp/$COUNT.png
convert +append /tmp/$COUNT.png $PLACE/$DATE.png
rm /tmp/$COUNT.png
let COUNT=$COUNT+1
done

optipng $PLACE/$DATE.png
convert -quality 95 $PLACE/$DATE.png $PLACE/jpg/$DATE.jpg


window shot:
#!/bin/sh

#take a screenshot from the currently active window

#requires imagemagick
#optionally uses optipng and xdotool

##########configurable##########
##
DATE=`date +%Y-%m-%d_%H:%M:%S`
PLACE=$HOME/Pictures/scrots
##
################################

mkdir -p $PLACE/jpg

import -window "$(xdotool getwindowfocus -f)" $PLACE/$DATE.png
optipng $PLACE/$DATE.png
convert -quality 95 $PLACE/$DATE.png $PLACE/jpg/$DATE.jpg


suspend the computer and lock the screen with a randomly selected picture:
#!/bin/sh

#Where the Lockscreen pictures are
LOCKFOLDER="$HOME/Pictures/Lockscreens"

RNDFILE=`ls $lockfolder | sort -R | tail -1`

i3lock -i $LOCKFOLDER/$RNDFILE
systemctl suspend
>>
Made this one today. Toggles the screen and mouse on and off off so tiny mouse movements wont turn the screen on again.
#!/bin/bash

state="$(xinput --list-props 9 | grep "Device Enabled")"
state="${state: -1}"

if [ "$state" == "1" ]
then
xinput --disable 9
xset dpms force off
else
xinput --enable 9
fi
>>
>gnu/linux
>the only OS where you script features to mimic other oses
>>
>>42131560
>GNU/Linux
>The only OS where you can script features
>>
>>42131616
that's not true

OS X comes with the BSD userland tools and a proper shell
>>
i alias a lot of long commands in my zshrc

alias msync='rsync -avHPe "ssh -pNNNN" --exclude imgs --exclude irclogs /media/ root@destination:/media/'

alias ampup='rsync -avHPe "ssh -pNNNN" ~/Music/ user@destination:/home/user/public_html/ampache/catalog/'
>>
.zshrc aliases
alias em='emacsclient -t'
alias ls='ls --color'
alias dir="dir --color=auto"
alias dmesg='dmesg --color'
alias diff='colordiff'
alias grep='grep --color=auto'
alias mkdir='mkdir -p -v'
alias ping='ping -c 5'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
alias rm=' timeout 3 rm -Iv --one-file-system'
alias clear=' echo -ne "\033c"'
alias cls='clear'
>>
>>42131694 again

i also have some that aren't long but make life easier when aliased

alias tc='tty-clock -sxcbt'
alias c='clear'
alias mailsrv='ssh -pNNNN [email protected]'
alias websrv='ssh -pNNNN [email protected]'
alias ll='ls -lah --color=always'
>>
~/bin/tunnel
ssh -f $1 -L $2:localhost:$2 -N

I suck at remembering flags.
>>
#!/bin/bash

SDIR=$(pwd)

if [ "$1" = "" ]
then
DIR=$SDIR
else
DIR=$1
fi

cd "$DIR"

echo -e "\e[7mCalculating replay gain values...\e[0m"
metaflac --add-replay-gain *.flac
>>
alias alias='alias'
>>
my newest unholy abomination (and proof that oh god, I am not good with this):

script that gives you the output of top for one or more running applications without having to know its pid

#!/bin/sh

if [ $# == 0 ]
then
echo `basename $0` 'needs at least 1 (one) argument'
exit 1
fi

top -bn 1 | head -n 7 | tail -n 1

for PROGRAMNAME in $@
do
top -p `ps -C $PROGRAMNAME -o pid | tail -n 1` -b -n 1 | tail -n 1
echo""
done


web'uhm related, it's the script in action

and no, I am not happy with that head|tail piping, it's merly a draft right now
>>
>>42131949
For this kind of use case, inefficient piping is acceptable.
>>
File: abc.webm (1 MB, 650x376) Image search: [Google]
abc.webm
1 MB, 650x376
Cuesplitter.
http://paste.kde.org/phgltm6fr
>>
I keep this script in /bin just incase something messes with my monitors, usually games ran with WINE
#!/bin/bash
xrandr -s 0
xrandr --output DFP10 --auto
xrandr --output DFP10 --right-of DFP11
>>
>>42131979
still, I would prefer to just grab the line I want..
using grep would probably be even less efficient than using head and tail, or?
>>
Encrypted backup
#!/bin/bash
tar czf /tmp/backup.tar.gz $@
aespipe -P /home/user/.backup_key </tmp/backup.tar.gz >/tmp/backup.tar.gz.aes
scp -P 22 /tmp/backup.tar.gz.aes backup_user@myhost:/home/backup_user/backup.tar.gz.aes
>>
I really need to learn about this (new-ish to linux here).

I had a load of .mkv files I wanted to run through ffmpeg just to change them to .mp4, how would one script this? I ended up doing it one by one and felt like a fool.

Any good learning resources y'all can point me to?
>>
>>42132035
grep does more precise string matching. Depending on the implementation, this might be more or less efficient than just splitting by line ends, like head and tail do. Either way, if you call this script less frequently than every second, you'll be fine.
>>

@echo off
echo 1) C:\1\images\waifu
echo 2) C:\1\images\pone
echo 3) C:\1\programs\tor
REM
REM
echo.
Set /P _option=Enter:
REM
REM
if "%_option%" == "1" (start C:\1\images\waifu)
if "%_option%" == "2" (start C:\1\images\pone)
if "%_option%" == "3" (cd "C:\1\programs\tor" & start tor.bat)
>>
>>42132054
Learn Bash. It's a simple script langage. You could have done something like:
for i in $(ls DIRECTORY | grep .mkv)
do
your_command( $i )
done
>>
This script checks a SATA-HDD for activity and in case of idleness will park it. It is very useful for servers. You can execute it on a regular basis via cron.
Needs sdparm installed



#!/bin/bash
#/scripts/hdd_ausschalten.sh
DISKNAME="sda"
let a=0
for i in `seq 0 100`
do
let a=`cat /proc/diskstats | grep $DISKNAME | mawk '{ print $(NF-2) }'`+a
sleep 0.1s
done
if [ $a == 0 ]
then
sdparm -C stop /dev/$DISKNAME
fi
exit 0
>>
here, have some aliases
alias df='df -h'                                    #human readable disk usage
alias du='du -h' #human readable folder usage
alias mkdir='mkdir -pv' #create subdirs, be verbose
alias ping='ping -c 5' #stop pinging
alias grep='grep --color=auto' #muh colors

#colors, human readable, trailing slashes etc
alias ls='ls --color=auto -hF --group-directories-first'

alias grephist='history | grep' #grep in the history file

alias pinstall='sudo zypper install'
alias psearch='zypper search'
alias premove='sudo zypper remove'
alias pupdate='sudo zypper patch && sudo zypper up'
alias pfullup='sudo zypper dup'

alias sudi='sudo -i'
>>
>>42131652
And if you're clueless you can use Automator to make your own scripts as well.
>>
anyone know of a good bash / shell script tutorial?

or would it be smarter to immediately learn a "proper" scripting language like perl or python?
>>
>>42132054
I am newish to Linux too
and I need to learn shell scripting too

i think you could have used wild cards in combination with a converter
>>
>>42131949
You should check out awk, you could script your entire thing in that while being efficient
>>
>>42131516
Not a script, but jq is a really useful for mangling JSON data on the command line.
>>
>>42132330
>>42132054
The Linux Command Line, great book and available for free on the interwebz
>>
>>42132495
thanks mate
>>
>>42132098
you could just do for file in *.mkv
>>
>>42131937
ty based anon, I use this everyday
>>
>>42131516
# Some shell functions

unpack () {
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) rar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "don't know how to extract "$1"..." ;;
esac
else
echo ""$1" is not a valid file!"
fi
}

stfu() {
("$@" 1>/dev/null 2>/dev/null &)
}

# Toggle vpn on/off
vpn() {
if ((systemctl status openvpn.service) | grep --quiet inactive)
then
echo "starting. . . .\n"
sudo systemctl start openvpn.service
else
echo "stopping. . . .\n"
sudo systemctl stop openvpn.service
fi
systemctl status openvpn.service
}

# Filter to get specific column of output
function awks {
first="awk '{print "
last="}'"
cmd="${first}\$${1}${last}"
eval $cmd
}

>>
since there seems to be no tool to extract the lines x to y from a file, I made one myself
enjoy this first, terrible draft
#!/bin/sh

if [ $# != 3 ]
then
echo "Usage: " `basename $0` " <startline> <endline> <filename>"
echo "Or: " `basename $0` " <startline> -<range> <filename>"
exit 1
fi


STARTLINE=$1
ENDLINE=$2
FILENAME=$3


# negative starting line is nonsense, set to 1
if [ $STARTLINE -lt 0 ]
then
STARTLINE=1
#echo "negative startline detected, assuming line 1 for startline"
fi


# if the endline is 0, assume the user wants only the specified (start) line
if [ $ENDLINE -eq 0 ]
then
tail -n+$STARTLINE $FILENAME | head -n 1
exit 0
fi


# negative endline means we're dealing with a range here
if [ $ENDLINE -lt 0 ]
then
ENDLINE=`expr 0 - $ENDLINE`
tail -n+$STARTLINE $FILENAME | head -n $ENDLINE
exit 0
fi


# probably malformed input
if [ $STARTLINE -ge $ENDLINE ]
# startline => endline, user probably meant to specify a range
then
echo "endline is equal to / lower than startline, assuming range"
echo ""
tail -n+$STARTLINE $FILENAME | head -n $ENDLINE
exit 0
fi


#regular case
#number is the amount of lines we wish to extract
NUMBERS=`expr $ENDLINE - $STARTLINE + 1`

tail -n+$STARTLINE $FILENAME | head -n $NUMBERS
>>
>>42131516
apt-get install shutter
>>
File: 2014-05-27_02:38:48.png (5 KB, 484x292) Image search: [Google]
2014-05-27_02:38:48.png
5 KB, 484x292
>>42134702
>40 packages
>28.3 MB
>for a screenshitter
I am become bloat, destroyer of GNU/Linux
>>
arch linux only

alias yolo="sudo pacman -Syu"
>>
>>42131616
Stay ignorant, fucktard.
>>
>>42134872
It has a lot of features that I find useful.
Are you on a chromebook c720, or something?
>>
>>42134913
this is quite easily ported to other distros:
alias yolo="sudo rm -rf `ls /etc | sort -R | tail -13
`
>>
>>42134519
>no tool to extract the lines x to y from a file
head -n 40 file | tail -n 10
>>
a handy file upload script so you dont have to use imgur or pomf, and you dont need some weird server or script

>well you need a webserver, but whatever

#!/bin/bash
echo "Enter the location of your file, or drag it to the terminal"
read fileloc
echo "Uploading your file..."
scp "$fileloc" user@your-ip:/path/to/symlink
echo "Done! your file has been uploaded."
filename=$(basename "$fileloc")
echo "You're file can be found at [ www.yoursite.com/up/$filename ]"


i've got it setup with a symlinked directory in the user root called up that symlinks to /usr/share/nginx/html/up/

im sure you can do it a different way, but this is super hand and decently secure (i hope).
>>
>>42135061
well, not as a single command, that's why I slapped that script together, to save me the hassle of having to pipe all that stuff together whenever I need to get lines 29 to 51 of whatever
>>
>>42131652
Stop being buttmad
>>
>>42135149
You can do it in one command with sed
sed -n 10,30p file

I give this a short name to make math on the command line easier.

#!/bin/sh
echo "$@" | bc
>>
>>42135103
lrn2errorhandling
>>
>>42135103
>you are file
>>
>>42136428
oh gosh, thanks for pointing that out
>>42136391
you put it in, its not like its ment to be supes srs, i just use it to throw le maymay pictures on my server to then post in IRC or whatever.
>>
>>42136464
>you put it in, its not like its ment to be supes srs, i just use it to throw le maymay pictures on my server to then post in IRC or whatever.
nigga error handling is the biggest reason to use helper scripts, so you can read up once on the various ways your program can fuck up and make a wrapper that suits your usage. it's easy.
>>
alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'

alias histgrep="history | grep -v 'history' | grep -E"

grab () { sudo chown $USER:$USER $1 }

mkcd () { mkdir $1; cd $1 }

cdl () { cd $1; ls }
>>
>>42135000
>i'm so funny guys laugh at me pls
>>
>>42136354
why not alias it?
>>
I go pretty light on the aliases.
alias eggsit="exit"
alias fag="sudo aptitude"
alias faggot="sudo aptitude install"
alias faggotry="sudo aptitude update && sudo aptitude full-upgrade"
alias whatisthis="hostname"
>>
>>42138777
... don't use aptitude. it is not really maintained well anymore.
>>
>>42138811
Is there a fork or something I should be using?
>>
>>42138823
no, just use apt-get.
>>
>>42138827
but muh dependency management
>>
>>42138838
lmao apt-get has dependency management and is much less likely to break your system.
>>
alias xgrep='xargs grep --color=always --line-number'


for "find . | xgrep filename"

I'm sure you could do something with "tree" or "grep", but I don't know it.

find . -print0 | xargs -0 grep $@
>>
>>42138842
explain
aptitude has never broken my system
>>
>>42138852
there's nothing to explain. use apt-get.
>>
>>42138867
But with apt-get I have to do sudo apt-get upgrade && sudo apt-get dist-upgrade whereas with aptitude i just have to do sudo aptitude full-upgrade.
>>
>>42138876
so? it is a better tool.
>>
>>42138947
You've failed to explain to me why it's better.
I've also done a cursory internet search, and everyone seems to agree with me.
>>
>>42138953
i have already explained. scroll up. also nice confirmation bias.
>>
>>42131516
> using backticks instead of $()
>>
>>42138960
I've literally not seen a single person who disagrees with me. Stop assuming things.

You haven't explained everything, the closest you've come is saying that it's not being maintained. I can't find any evidence of that, so if it's true, please cite your source.
>>
Not sure how to do this in bash. Sorry.
[anon@nsa ~]$ cat /usr/bin/isup
import urllib2,sys

isup = 'http://isup.me/'
isup = isup+sys.argv[1]

try:
src = urllib2.urlopen(isup).read()
if 'not just' in src.lower():
print sys.argv[1]+' is down.'
else:
print sys.argv[1]+' is up.'
except:
print 'Error connecting to isup.me.'
>>
>>42131920
> using old test operator
> not quoting variables
> not using ${} for variable substitution
>>
>>42138966
This is useless in the world of CDN's. Example: 4chan and half of the Internet is down for me because Cloudflare's servers in Warsaw are kill but this site reports that everything is fine because it uses a totally different one.
>>
>>42138965
i'm not going to bother. if you want to continue using aptitude, i can't stop you.
>>
>>42138990
Because you're a retard.
I'll continue using my superior tool.
>>
>>42138966
just use netcat and grep.
>>
>>42138994
Because you're a retard.
I'll continue using my superior tool.

(see, anybody can do that)
>>
>>42139000
You're not giving much choice here, with your retarded argument, with zero evidence and incredibly flimsy supporting points.
>>
>>42139012
I just don't want to waste my time arguing about package managers anymore. Do your own research, and if you feel like you're using the right thing, then use it.
>>
>>42139020
Yet you continue to shitpost incessantly, suggesting that rather than not wanting to argue, you are incapable of supporting your argument, but also incapable of admitting that you're wrong because of your crippling autism.
>>
>>42139023
Is it really that satisfying to your fragile psyche to insult strangers on the internet?
>>
>>42139037
It's honestly more satisfying in real life, but putting idiots in their place on the internet is fine too.
>>
>>42139043
Just reflect on that for a while.
>>
>>42139056
Ditto.
>>
File: 1400474826302.webm (3 MB, 1366x768) Image search: [Google]
1400474826302.webm
3 MB, 1366x768
This is a webm script that creates a webm of the time in between two screenshots.

Unfortunately the screenshots have to have filenames formatted a certain way: videofilename.mkv<time>
You can use put
screenshot-template="/home/user/downloads/%f<%P>"
in your mpv .config

The working directory has to contain the video.

But essentially this allows me to create webms incredibly quickly just by taking 2 screenshots in mpv and dragging them to the terminal. I also have a version that adds subtitles.

The first three lines are the only important parameters: output filename, bitrate, and scale (height)

#!/bin/bash

out__="out"
bitra="004"
scale="540"

##############

cap1="$1"
cap2="$2"

input0=${cap1##*/}
input=${input0%%\<*}
#try location later

start0=${cap1#*\<}
start=${start0%%\>*}

end0=${cap2#*\<}
end=${end0%%\>*}

title0=${input#*\]}
title=${title0%%\[*}

ffmpeg -itsoffset $start -ss $start -i "$input" -ss $start -to $end -vf scale=-1:$scale -b:v "$bitra"M -crf 4 -an -sn -bufsize 99M -auto-alt-ref 1 -lag-in-frames 16 -quality good -cpu-used 0 -threads 0 -pass 1 -metadata title="$metat" -y -f webm /dev/null && \
ffmpeg -itsoffset $start -ss $start -i "$input" -ss $start -to $end -vf scale=-1:$scale -b:v "$bitra"M -crf 4 -an -sn -bufsize 99M -auto-alt-ref 1 -lag-in-frames 16 -quality good -cpu-used 0 -threads 0 -pass 2 -metadata title="$metat" -y "$out__.webm" && rm ffmpeg2pass-0.log
mpv --loop=inf "$out__.webm"
>>
>>42131560
windows, the only os where you cant do anything with a fresh install. Enjoy jour notepad, mspaint telnet, bing and ie integration.
>>
Waiting for your server to come up back after a reboot?

#!/bin/bash

decho() { echo `date +%x-%X`: $@ ; }

if [[ $@ == "" ]]; then
echo "You didn't specify a host, so I'm pinging 4.2.2.1"
ip=4.2.2.1
else
ip=$@
fi

while sleep 1; do
if ping -qc1 -W1 $ip 1> /dev/null 2> /dev/null; then
decho "Host is back!"
if which beep 1> /dev/null 2> /dev/null; then ( beep -f 1000 -l 100 -r 5 & ); fi
if which notify-send 1> /dev/null 2> /dev/null; then (notify-send "Host is back" & ); fi
if which aplay 1> /dev/null 2> /dev/null; then (yes ddd|aplay -q 1> /dev/null 2> /dev/null) & ( sleep 1 ; killall aplay ); fi
exit 0
else
decho "Nothing yet..."
fi
done

>>
https://github.com/friendlyanon/4chan-thread-archiver

How'd I do?
>>
>>42139092

God I miss that show.
>>
>>42139092
I made something similar. It re-encodes a video into equal 3MB seperate webms.

#!/bin/bash

crf=18
bitrate=500K
threads=8

duration=$(expr `mediainfo --Inform="General;%Duration%" "$1"` / 1000)
sec=0
j=1

until (($sec >= $duration))
do
ffmpeg -ss $sec -i "$1" -an -sn -threads $threads -c:v libvpx -crf $crf -b:v $bitrate -fs 3M $j.webm
sec=$(expr $(expr `mediainfo --Inform="General;%Duration%" $j.webm` / 1000) + $sec)
j=$((j+1))
done
>>
>>42139217
Grepping HTML is always a bad idea, tomorrow 4chan changes something in its code and you have to rewrite it.

Just use the JSON API.
>>
File: 1400474751798.webm (181 KB, 960x540) Image search: [Google]
1400474751798.webm
181 KB, 960x540
>>42139225
I-I'm sure we'll get a season 2 as soon as there's enough source material. And maybe someone will pick up translations!
>>
This allows you to automatically get updates for manga releases from mangupdates.com, something very daunting or hard otherwise, at least without being locked into some crappy website. There's no proper RSS feeds for this or anything.

Just add links to the manga you want in manga_array, and run it with cron at least once a day. If it finds an update it will leave an executable file in your home folder which launches firefox on the page for the manga.

#!/bin/bash
mkdir -p $HOME/.baka_updates
cd $HOME/.baka_updates
update_file=$HOME/New\ Manga

manga_array=(
"https://www.mangaupdates.com/releases.html?search=38312&stype=series" # Amanchu
"http://www.mangaupdates.com/releases.html?search=62896&stype=series" # Chimoguri Ringo
"http://www.mangaupdates.com/releases.html?search=43241&stype=series" # I am a Hero
"https://www.mangaupdates.com/releases.html?search=94116&stype=series" # Koe no Katachi
"http://www.mangaupdates.com/releases.html?search=106871&stype=series" # Kotonoba Drive
"http://www.mangaupdates.com/releases.html?search=48607&stype=series" # Ryuushika
"http://www.mangaupdates.com/releases.html?search=40342&stype=series" # Tonnura-san
"http://www.mangaupdates.com/releases.html?search=68820&stype=series" # Watamote
"http://www.mangaupdates.com/releases.html?search=5&stype=series" # Yotsuba
)

today=`date +%D`
yesterday=`date -d "yesterday" +%D`

update() {
echo $link $1 >> mangadb
echo firefox \"$link\" >> "$update_file"
chmod +x "$update_file"
echo Found update.
}

for link in ${manga_array[@]}
do
wget -q $link -O temp
if grep -q $today temp ; then
if ! grep -q "$link $today" mangadb ; then
update $today
fi
elif grep -q $yesterday temp ; then
if ! grep -q "$link $yesterday" mangadb ; then
update $yesterday
fi
fi
rm temp
done
>>
>>42139275

Now that is brilliant.
>>
>>42139258
I've been tweaking it all the time, it's more like for personal use I just shared it with someone who was in charge for archiving a quest more than a year ago. And I don't know how to deal with JSON in Shell to male it work on Android as well (remember that this is for personal use mainly). Still no WebM support in the 4chanX injected which I haven't bothered with yet because I used some minimizer and I don't have the original anymore.
And I still need to find a way to preserve deleted posts.
>>
Dirty ass hack to download all images from many imageboards/archives, and all images on danbooru of a certain tag.

It just takes the link to the thread as an argument. e.g.
qget >>42139217


http://pastebin.com/RBASdFCf
>>
I use this function in my shellrc to get rid of the names of some images I post on 4chan:

erasefilename() {
local base="$(basename "$1")"
local name="${base%%.*}"
local rand="$RANDOM$RANDOM"
echo "$name -> $rand"
rename "$name" "$rand" "$1"
}
>>
>>42139444
>line 44
> [e]
What's the point?
>>
>>42139505
Yeah I know I didn't do it for the other sites.

Rarely some people upload images with a ".jpeg" extension and many sites accept it as is. Another thing is with the capital ".JPG" and ".PNG" extensions.

I basically made this so if I ever wanted to I could very quickly add any site I wanted to a one-in-all script to download images from any site, and that's pretty much what I did. A rampage of grepping regex on html for a bunch of sites.

It works though I mean, I can quickly download all images from threads or whatever on any of those sites, and it's very modular so you can just add in any site you want later on.

Of course it's dirty as fuck, a lot of the regex isn't even uniform and it's all mis-matched, it could be easily cleaned up though.
>>
>>42139570
I mean that regex is wrong:
root@jflte:/storage/extSdCard/wps/save # echo jpg | egrep 'jp[e]g'
root@jflte:/storage/extSdCard/wps/save #

you should use e? instead of [e]
>>
Since I'm a filthy pleb that doesn't sort his chinese cartoons, I use this a lot.
function play() {
if [ -z ${1} ] ; then
echo "play: Invalid number of parameters."
return
fi

FILES=$(ls)
for ARG in $@
do
FILES=$(echo "$FILES" | grep -i "$ARG")
done

if [ -z "$FILES" ]; then
echo "play: Terms \"$@\" not found."
return
fi

while read -u 3 FILE; do
if [[ "$ANS" != "a" ]]; then
ANS=""
fi

while [[ "$ANS" == "" ]]; do
read -n 1 -p "Play $FILE [y/n/a/q]? " ANS && echo ""
done

if [[ $ANS == "y" || $ANS == "a" ]]; then
echo "Playing $FILE"
mplayer -fs "$FILE"
elif [ $ANS == "q" ]; then
return
fi
done 3<<<"$FILES"
unset FILES
unset FILE
unset ANS
}

I was going to add operands but I never got around to it.
Usage: play chaika 08
>>
>>42138759
>alias histgrep="history | grep -v 'history' | grep -E"
Noy him, but how would you alias that pipe, when you need to put some argument after the pipe.
>>
>>42139610
You're right.

Not sure what I was thinking, could have sworn I read a guide telling me to do something like that and it worked somehow.
>>
>>42132054
for f in *.wav; do ffmpeg -i "$f" -ab 320k "${f%.wav}.mp3"; done

Change the file extensions as needed.
>>
>>42132054
Someone here pointed this one out:
[code}#!/bin/bash
mkdir -p T43p

rescale=no
res="1280:720"
mapper="-map 0 -c copy" #default: "-map 0 -c copy"

test $rescale == no
if (($? == 0))
then
for a in *.mkv
do
ffmpeg -i "$a" $mapper -c:v libx264 -crf 18 -tune animation -preset veryfast T43p/"$a"
done
else
for a in *.mkv
do
ffmpeg -i "$a" $mapper -c:v libx264 -crf 18 -tune animation -preset veryfast -vf scale=$res T43p/"$a"
done
fi[/code]
>>
>>42139710
That's mine actually.

#!/bin/bash
mkdir -p T43p

crf=18
preset=veryfast

rescale=yes
res="-1:720"

if test $rescale == no
then
for a in *.mkv
do
ffmpeg -i "$a" -map 0 -c copy -c:v libx264 -crf $crf -preset $preset -tune animation "T43p/$a"
done
else
count=0
for a in *.mkv
do
ffmpeg -i "$a" -map 0 -c copy -c:v libx264 -crf $crf -preset $preset -tune animation -vf scale=$res "T43p/$a" &
let count+=1
[[ $((count%4)) -eq 0 ]] && wait
done
fi


This is to actually re-encode all the video in a directory. I only use it to re-encode 10bit and/or 1080p video to 8bit and/or 720p to run on my slower computer.

He just wants to change the container? Easy.

for vid in *.mkv ; do
ffmpeg -i "$vid" -c copy "${vid%.mkv}.mp4"
done
>>
>>42138876
So make an alias. WELCOME TO THE THREAD.
>>
File: leet.jpg (95 KB, 1770x655) Image search: [Google]
leet.jpg
95 KB, 1770x655
>>42131516
>>
>>42131516
or just use scrot and scrot -s
>>
>>42134913
How is that "yolo", you're just updating packages. Try this: alias yolo='yaourt -Sfyyua --devel --noconfirm --insecure --force --really-force -vv --debug --color always --skipchecksums'
>>
One of my most helpful.
# run tsocks with temporary conf file
# socksify host port program [arguments]
socksify()
{
host="$1"
port="$2"
shift 2
tempfile="`mktemp`"
cat > "$tempfile" << EOD
server = $host
server_port = $port
EOD
TSOCKS_CONF_FILE="$tempfile" tsocks "$@"
rm "$tempfile"
}
>>
>>42131898
You should check out "man ssh_config".
>>
>>42138978
> > not using ${} for variable substitution
It's only useful when you have alphanumeric characters directly after your variable.
>>
>>42132111
Fucken saved, bro.
>>
>>42139275
I'm using alertbox for firefox. Pretty sure it's working with mangas.
>>
>>42134872
>perl-common-sense
I fucking knew that common sense is optional in perl.
>>
>>42138852
It did for me.
In fact in 2 months aptitude caused me more problems than pacman in the last 3 years.
>remove something
>suddenly aptitude wants to remove linux, glibc
>can completely lose track of the system if you use dpkg, ending up suggesting fixes where you have to remove packages you don't even have installed

It's basically one of the examples when an application tries to be smarter than you and utterly fails at it.
>>
>>42139092
Wow, that's simple.
I ended up patching Blender to export webms to achieve the same.
>>
I used to have a ton of aliases that unfortunately got lost after a hard disk failure.

the one's I have now are fairly obvious:
alias ll='ls -laF'
alias yinst='yaourt -S'
alias inst='sudo pacman -S'
alias upd='sudo pacman -Syu'
alias svim='sudo vim'
alias uinst='sudo pacman -Rs'
alias part='df -h'
alias pingg='ping www.google.com'


I also have one for restarting wifi, since it keeps fucking up sometimes.

alias rwifi='sudo rmmod iwldvm iwlwifi && sleep 1s && sudo modprobe iwldvm iwlwifi'
>>
#!/bin/zsh
n=$1

if [[ $2 == "-f" && -d $3 ]]; then
dest=$3
else
dest=.
fi

if [[ n -le 0 ]]; then
echo invalid number
else
IFS=$'\n' files=( $(ls -t /home/zeta/Downloads/*(.om[0,$n])) )
print -C 1 $files

echo
echo "Copy - c" "Move -m"
read op

ops=(m c)
if [[ ${ops[(r)$op]} != $op ]]; then
echo invalid option
echo exiting.
exit
fi

echo "destination: $dest"
for file in $files
do
if [[ $op == "c" ]]; then
cp $file .
echo "copied $file"
elif [[ $op == "m" ]]; then
mv $file .
echo "moved $file"
fi
done
fi


Use to list the n most recently added files from the Download folder. You get the choice to move/copy the n files to your current directory. I use this one all the time. However, it's not bash-compatible without some of it extensions.

function cde () {
dirs=$(emacsclient --eval '(with-current-buffer (window-buffer (selected-window)) (personal-current-dir))')
dirs="${dirs%\"}"
dirs="${dirs#\"}"
echo $dirs
cd "$dirs"
}


Used to change dir to the current working directory of the active emacs frame. It only works if you use the emacs deamon, though.
>>
resets dpms every 50 seconds so the screen doesn't suspend.

#!/bin/bash

while true; do
sleep 50s
xset -dpms
xset dpms
done
>>
>>42140896
Why not just use yaourt for everything?
>>
>>42140896
>hard disk failure
just upload your scripts and configs to github
or dropbox, if your scripts are proprietary and for the eyes of the NSA only
>>
>>42140934
why should I? yaourt is just an extra layer on top of pacman.

I use it explictly for aur packages, nothing more.

>>42140947
yeah I'm backing up everything now on a regular basis.
>>
>>42140477
Because updating on Arch is always living on the edge.
>>
>>42140477
>--noconfirm --insecure --force --really-force
l-lewd!
>>
>>42140921
why not just "xset -dpms" once?
>>
>>42141053
I used to do that but I'd always forgot to turn it back on after watching a movie.
>>
>>42139092
Now that is pretty neat.
>>
>>42131766
>using clear
Press Ctrl+L, dummy
>>
>>42140921
# usage: nodpms mpv ...
function nodpms (){
xset -dpms
"$@"
xset +dpms
}
>>
>>42133439
>stfu
why not &> /dev/null ?
>>
>>42131766
> ssh to root account
>>
>>42141118
I always forget and type clear. I just can't change this habit.
>>
>>42139012
>>42139020
>>42139023
>>42139043
>>42139056
>>42139067
Everything that's great about 4chan right here.
>>
>>42141212
Because this is /g/, and we are fools.
>>
>>42139486
why would you do that?
>>
>>42140964
>why should I?
because it wraps everything pacman does, you could alias pacman to yaourt and it'd just be pacman with color and aur support
>>
>>42139092
>>42140893
>I ended up patching Blender to export webms
Holy shit what

Also, do you know that mpv has nice commands for that? You don’t need to abuse screenshots, you can just use the run command and pass it some properties, like "${path}" "${=time-pos}" "${=sid}" "${sub-visibility}" etc.
>>
Google image search

#!/usr/bin/env python

import json
import sys
import urllib
import urllib2

GOOGLE_IMAGE_SEARCH = 'http://ajax.googleapis.com/ajax/services/search/images'

def search(term, n=5):
query = urllib.urlencode({
'v': '1.0',
'q': term,
'safe': 'off'})
url = '%s?%s' % (GOOGLE_IMAGE_SEARCH, query)
response = json.loads(urllib2.urlopen(url).read())
if response['responseData']:
return [
result['unescapedUrl']
for result in response['responseData']['results'][:n]]

if __name__ == '__main__':
term = ' '.join(sys.argv[1:])
results = search(term)
if results:
print '\n'.join(results)
else:
print 'No results found.'
>>
blurred screenshot as lockscreen

#!/bin/bash
convert x:root -blur 0x8 /tmp/lockscreen.blur.png
i3lock -i /tmp/lockscreen.blur.png
>>
Quick cmdline search of urban dictionary

#!/usr/bin/env python

import json
import sys
import urllib
import urllib2

def search(term):
query = urllib.urlencode({
'page': '1',
'term': term})
fh = urllib2.urlopen('http://api.urbandictionary.com/v0/define?%s' % query)
data = json.loads(fh.read())
if len(data['list']):
return data['list'][0]['definition']
return 'No result found'

if __name__ == '__main__':
term = ' '.join(sys.argv[1:])
print search(term)
>>
>>42131949
>pgrep
>>
>>42133439
you can save some lines by using
tar xf
tar will know what to use itself
>>
>>42139092
clever
>>
>>42142702
>>I ended up patching Blender to export webms
Piss easy, about 10 lines, blender already using ffmpeg, all you need to add is webm output (container is choosen by using file extension), and the VP8/9 codec.
Didn't send it in yet as VP9 rendering crashes if you cancel it before the first frame is completed and I don't know why is that.
>>
>>42142776
could not just use urllib2?
>>
sudo apt-get autoremove
>>
Fix for if you don't want to see your mouses battery in the power manager.

function unifying(){
sudo cp /lib/udev/rules.d/95-upower-csr.rules /etc/udev/rules.d/95-upower-csr.rules
sudo sed 's/, ENV{UPOWER_BATTERY_TYPE}=\"unifying\"//g' -i /etc/udev/rules.d/95-upower-csr.rules
}

unifying
>>
>>42143539

And fix for if you use an AR9462 chipset and wifi keeps shitting out.

kernelver=$(uname -r | cut -d- -f1)

function wififix(){
if [ $(echo "$kernelver >= 3.12" | bc -l) ];
then
echo "options ath9k nohwcrypt=1 blink=1 btcoex_enable=1 bt_ant_diversity=1" | sudo tee /etc/modprobe.d/ath9k.conf
else
echo "options ath9k nohwcrypt=1 blink=1 btcoex_enable=1 enable_diversity=1" | sudo tee /etc/modprobe.d/ath9k.conf
fi
}

wififix
>>
Easily install nvidia drivers in debian

#!/bin/bash
apt-get install module-assistant nvidia-kernel-common &&
m-a auto-install nvidia-kernel${VERSION}-source &&
apt-get install nvidia-glx${VERSION} &&
cat > /etc/X11/xorg.conf << EOF
Section "Module"
Load "glx"
EndSection

Section "Device"
Identifier "Video Card"
Driver "nvidia"
EndSection
EOF
>>
#!/bin/bash
git clone "http://github.com/$1/$2.git"


script username reponame
>>
>>42142785
wot, thanks mate, wasn't aware that existed

so, this'd be the "new and improved" version of topthis
#!/bin/sh

if [ $# == 0 ]
then
echo `basename $0` 'needs at least 1 (one) argument'
exit 1
fi

PIDS=""
for PROGRAMNAME in $@
do
#get the PIDs of the Programs via pgrep
PIDS="$PIDS`pgrep $PROGRAMNAME` "
done

#use sed to replace the spaces with commas, so top can read this
PIDS=`echo $PIDS | sed 's/ /,/g'`

#output sans the first 7 lines (top's header / summary)
top -p $PIDS -bn1 | tail -n+7

echo ""
>>
>>42142767
I like this. An adjustment I made though darkens the image slightly and decreases the blur, which I prefer.
convert x:root -brightness-contrast -50x0 -blur 0x4 /tmp/lockscreen.blur.png


Takes a bit longer though.
>>
>>42144501
>>42142767
What package do i have to install to get the convert command?
>>
>>42144893
imagemagick
>>
>>42145068
ty
>>
>>42144243
glad to help
pgrep and pkill with zsh shell is absolute perfection (tabcompleting names of processes)
also look at pgrep arguments, you can easily filter all the different threads of some process, or only show processes of some user etc...
>>
all mine are short and simple, like xset -dpms; xset s off becomes 'nosleep' and my cgminer startup script becomes dogemine or litemine etc.

I guess I could makes ones with arguments for shit like making webms. one day
>>
Anybody know of a script to browse the Arch wiki?
>>
I really like these threads 339
>>
>>42144243
That's neat, scriptbro.
>>
>>42142754
What would the output be like/ I'm on my phone , cant check
>>
>>42145788

It prints the direct image URLs
>>
>>42142754

Note if you have python3 also you have to state python2 at the top.
>>
>>42131560
You do realize that as an OS, linux has more functionality than windows, right?
>>
>>42131516
A little script I wrote that whispers remaining battery percent every minute. Depends on espeak and grep.
while true
do
acpi | grep -o -e Battery -e , -e ..% | espeak -ven-us+whisper -s 130 -a 10 -p 1 --stdin
sleep 60
done


Reminds me of Lain. I find it very enjoyable.
>>
>>42148267
That sounds creepy as fuck.
>>
>>42134519
sed -n "42,50p"
>>
>>42148267

If you don't have acpi installed

cat /sys/class/power_supply/BAT0/capacity
>>
>>42150037

Or if the battery name is different

cat /sys/class/power_supply/BAT*/capacity
>>
I've seen some wget scripts (the best one I saw was just a wget command with a million flags) floating around for archiving entire 4chan threads. Anyone have one?
>>
>>42150267
What do you mean by "archiving entire 4chan threads"?

Downloading a 4chan thread is piss easy

wget -p -m --accept-regex="4cdn.org" >>42131516
>>
Anyone wanna write me a script to make a swastika out of swastikas, or link one as I'm sure one exists? :^)
>>
>>42150724
>The source of the page, the images, and the thumbnails linking everything together locally.
>>
>>42150055

better use '?' then
>>
>>42150789
Put -k to convert links to local
Put -P .\directory to have it in one directory

Really this is elementary stuff
>>
>>42150834
Thanks, and me and your mother are real proud of you for knowing stuff.
>>
>>42151009
Gee wiz bro, if you didn't want help why did you ask?
>>
USS Enterprise mode:
play -n -c1 synth whitenoise lowpass -1 120 lowpass -1 120 lowpass -1 120 gain +14


requires the SoX framework, which is pretty much standard on pretty much all distro but we do have some extreme minimalists in here too.
>>
>>42152265
how do i do this on windows?

downloaded sox.exe but doesn't work
>>
>>42152430
it's probably play.exe or something, I don't know. I don't use windows.
>>
>>42152504
>>42152430
seems to be a seperate executable, so yea, you'd need a "play.exe"
$ head $(which play) | file -
/dev/stdin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), stripped
>>
>>42154016
>head $(which play)

Why the head...

file $(which play)
/usr/bin/play: symbolic link to `sox'


So through your unnecessary code you managed to ignore that play is a symlink to sox.
>>
test
>>
>>42147973
>"You do realize...."

That's like the reddit trademark catchphrase. Go back to reddit you fucking cocksucker.
>>
>>42144893
If you are on a deb based distro I recommend apt-file for these kind of questions in the future.
>>
>>42143586
I would make a backup for xorg.conf before overwriting
>>
>>42134913
Ok I lol'ed
Thread replies: 186
Thread images: 9

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.