You are not logged in.
Total, blank, non-blank:
wc -l < $filename
grep -c '^$' $filename
grep -cv '^$' $filenameLast edited by karol (2012-08-24 16:52:49)
Offline
You should probably check out `wc`, specifically `wc -l` to get the total lines, and
grep -v "^ *$" filename | wc -lto get a nonblank line count.
Edit: too slow ... but I just learned about grep's -c option. Cool.
Last edited by Trilby (2012-08-24 16:55:17)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Damn, @karol is right
The fact is that i wanted the script to detect CRLF also, but then I discovered dos2unix....and then it seems I forgot about wc... : (
Anyway, it was good for my bash learning : P
Offline
This is a beautiful way I run Radio Paradise. Though, most other internet radio stations would work with a simple URL switch.
#!/bin/zsh
kill -9 `ps x | grep "mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput http://stream-sd.radioparadise.com:9000/rp_32.ogg" | grep -v "grep" | cut -f 2 -d\ ` 2>/dev/null
if [ $? = 1 ]; then
mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput http://stream-sd.radioparadise.com:9000/rp_32.ogg &
fiLast edited by pilotkeller (2012-08-26 01:47:42)
Offline
This is a beautiful way I run Radio Paradise. Though, most other internet radio stations would work with a simple URL switch.
#!/bin/zsh kill -9 `ps x | grep "mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput http://stream-sd.radioparadise.com:9000/rp_32.ogg" | grep -v "grep" | cut -f 2 -d\ ` 2>/dev/null if [ $? = 1 ]; then mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput http://stream-sd.radioparadise.com:9000/rp_32.ogg & fi
Why not use 'pkill mplayer' to kill it?
Offline
Because one never knows what instance pkill kills?
Offline
Because one never knows what instance pkill kills?
Not sure if I get what you mean, but would
kill -9 $(pgrep -fo radioparadise)be better?
Offline
Maybe somethinng like:
{ mplayer ... & pid=$!; }; wait; kill $pid Offline
Why not use 'pkill mplayer' to kill it?
Because I often watch lectures and then pause them as my mind hits the wall. This would kill them.
kill -9 $(pgrep -fo radioparadise)
Problem is that mplayer threads into two for web streams so the script would run twice before it worked as intended.
{ mplayer ... & pid=$!; }; wait; kill $pid
And this is why I wrote the script. The content is a stream, so it never exits. lol
MISTAKE: cut -f 2 should be cut -f 1 -- This came from starting with ps aux but changed it to limit entries.
Last edited by pilotkeller (2012-08-26 17:03:38)
Offline
karol wrote:kill -9 $(pgrep -fo radioparadise)Problem is that mplayer threads into two for web streams
I know.
so the script would run twice before it worked as intended.
Seems to work for me - I just need to run it once and 'kill' works w/o the '-9' flag too:
kill $(pgrep -fo radioparadise)Offline
Seems to work for me - I just need to run it once and 'kill' works w/o the '-9' flag too:
kill $(pgrep -fo radioparadise)
Lions, and Tigers, and Shell, OH MY!
When you send SIGTERM vs SIGKILL it stops both! ![]()
#!/bin/zsh
kill $(pgrep -fo radioparadise) 2>/dev/null
if [ $? = 1 ]; then
mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput http://stream-sd.radioparadise.com:9000/rp_32.ogg &
fiThanks karol! <3
Offline
@Karol: The problem is any 'radioparadise' will match. Eg:
$ vim radioparadise
$ pgrep -fo radioparadiseLast edited by steve___ (2012-08-26 17:32:34)
Offline
If there is that much worry just use
#!/bin/zsh
stream_url="http://stream-sd.radioparadise.com:9000/rp_32.ogg"
kill $(pgrep -fo $stream_url) 2>/dev/null
if [ $? = 1 ]; then
mplayer -msglevel all=-1 -noconsolecontrols -nojoystick -nolirc -nomouseinput $stream_url &
fiLast edited by pilotkeller (2012-08-26 17:42:40)
Offline
@Karol: The problem is any 'radioparadise' will match. Eg:
$ vim radioparadise $ pgrep -fo radioparadise
Sure, but e.g.
kill $(pgrep -fo stream-sd.radioparadise)is less likely to cause problems.
Edit: Too late ;P
When you send SIGTERM vs SIGKILL it stops both!
The '-o' flag of pgrep acts against the oldest process, otherwise you get an error about the other (newer) process being already gone:
$ pgrep -f stream-sd.radioparadise
1946
1947
$ kill $(pgrep -f stream-sd.radioparadise)
bash: kill: (1947) - No such processLast edited by karol (2012-08-26 17:42:57)
Offline
pilotkeller wrote:When you send SIGTERM vs SIGKILL it stops both [threads]! :O
No no. When you run plain kill it sends a SIGTERM. The -9 makes it a SIGKILL. Although a SIGTERM is always prefered, many programs don't handle SIGTERMs so SIGKILL is what gets used by habbit. lol
Edit: Probably my bad for the :O. The icon makes it more paniced then shocked. lol
Last edited by pilotkeller (2012-08-26 17:54:27)
Offline
Ah, now I get what you meant.
BTW,
pkill -f "http://stream-sd.radioparadise.com:9000/rp_32.ogg"works too ;P
Offline
Here is a basic script I wrote in just a few minutes to take a xresources colorscheme and print out a reg file to import in windows for use with putty/kitty. By default, it sets the registry path for use with Kitty, but I put another line in there that can be un-commented to use with putty. Could be improved, but I thought I'd share so others can make it better!
Usage: Pass a .Xdefaults file or file containing colors
Example:
> xcolorstoreg.sh .Xdefaults
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\Default%20Settings]
"Colour0"="220,220,204"
"Colour1"="220,220,204"
"Colour2"="58,58,58"
"Colour3"="58,58,58"
"Colour4"="220,220,204"
"Colour5"="220,220,204"
"Colour6"="30,35,32"
"Colour7"="112,144,128"
"Colour8"="112,80,80"
"Colour9"="220,163,163"
"Colour10"="96,180,138"
"Colour11"="195,191,159"
"Colour12"="223,175,143"
"Colour13"="240,223,175"
"Colour14"="80,96,112"
"Colour15"="148,191,243"
"Colour16"="220,140,195"
"Colour17"="236,147,211"
"Colour18"="140,208,211"
"Colour19"="147,224,227"
"Colour20"="220,220,204"
"Colour21"="255,255,255"Source:
#!/bin/bash
xfile=$1
fallbackbg="0,0,0"
fallbackfg="170,170,170"
function hex2rgb () {
hexinput=$1
a=`echo $hexinput | cut -c-2`
b=`echo $hexinput | cut -c3-4`
c=`echo $hexinput | cut -c5-6`
r=`echo "ibase=16; $a" | bc`
g=`echo "ibase=16; $b" | bc`
b=`echo "ibase=16; $c" | bc`
echo "$r,$g,$b"
}
while read line
do
colorname=$(echo $line | tr [:lower:] [:upper:] | sed 's/:.*//g' | sed 's/.*\*//g')
hexcolor=$(echo $line | tr [:lower:] [:upper:] | sed 's/.*#//g')
case "$colorname" in
FOREGROUND)
foreground=$(hex2rgb $hexcolor)
;;
BACKGROUND)
background=$(hex2rgb $hexcolor)
;;
COLOR0)
black0=$(hex2rgb $hexcolor)
;;
COLOR8)
black1=$(hex2rgb $hexcolor)
;;
COLOR1)
red0=$(hex2rgb $hexcolor)
;;
COLOR9)
red1=$(hex2rgb $hexcolor)
;;
COLOR2)
green0=$(hex2rgb $hexcolor)
;;
COLOR10)
green1=$(hex2rgb $hexcolor)
;;
COLOR3)
yellow0=$(hex2rgb $hexcolor)
;;
COLOR11)
yellow1=$(hex2rgb $hexcolor)
;;
COLOR4)
blue0=$(hex2rgb $hexcolor)
;;
COLOR12)
blue1=$(hex2rgb $hexcolor)
;;
COLOR5)
magenta0=$(hex2rgb $hexcolor)
;;
COLOR13)
magenta1=$(hex2rgb $hexcolor)
;;
COLOR6)
cyan0=$(hex2rgb $hexcolor)
;;
COLOR14)
cyan1=$(hex2rgb $hexcolor)
;;
COLOR7)
white0=$(hex2rgb $hexcolor)
;;
COLOR15)
white1=$(hex2rgb $hexcolor)
;;
*)
echo "WTF!" > /dev/null
;;
esac
done < $xfile
if [ -z "$foreground" ]; then
foreground=$fallbackfg
fi
if [ -z "$background" ]; then
background=$fallbackbg
fi
echo "Windows Registry Editor Version 5.00"
echo ""
# FOR USE WITH PUTTY
#echo "[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]"
# FOR USE WITH KITTY
echo "[HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\Default%20Settings]"
echo -e "\"Colour0\"=\"$foreground\""
echo -e "\"Colour1\"=\"$foreground\""
echo -e "\"Colour2\"=\"$background\""
echo -e "\"Colour3\"=\"$background\""
echo -e "\"Colour4\"=\"$foreground\""
echo -e "\"Colour5\"=\"$foreground\""
echo -e "\"Colour6\"=\"$black0\""
echo -e "\"Colour7\"=\"$black1\""
echo -e "\"Colour8\"=\"$red0\""
echo -e "\"Colour9\"=\"$red1\""
echo -e "\"Colour10\"=\"$green0\""
echo -e "\"Colour11\"=\"$green1\""
echo -e "\"Colour12\"=\"$yellow0\""
echo -e "\"Colour13\"=\"$yellow1\""
echo -e "\"Colour14\"=\"$blue0\""
echo -e "\"Colour15\"=\"$blue1\""
echo -e "\"Colour16\"=\"$magenta0\""
echo -e "\"Colour17\"=\"$magenta1\""
echo -e "\"Colour18\"=\"$cyan0\""
echo -e "\"Colour19\"=\"$cyan1\""
echo -e "\"Colour20\"=\"$white0\""
echo -e "\"Colour21\"=\"$white1\""Last edited by brenix (2012-08-29 16:29:08)
Offline
I use dropbox for storing some backups. This is a script i have made to fully automate it. I use gpg encryption of tar file too when uploading to dropbox.
#!/bin/bash
echo "Compressing folders..."
echo
echo
tar cvf $(date +%d-%m-%Y).tar /path/to/folders/you/want/to/backup;
echo
echo
echo "Done. Encrypting. Write a password...";
gpg -c $(date +%d-%m-%Y).tar;
echo "Moving to dropbox folder";
echo
mv $(date +%d-%m-%Y).tar.gpg /pathofyour/dropbox/folder;
echo "Removing tar file";
rm $(date +%d-%m-%Y).tar;
echo "tar file removed";
echo "Initializing dropbox daemon";
dropboxd &
sleep 180s;
echo "Closing dropbox daemon";
killall dropbox;
echo "Done!"If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Shark,
nice.
Mektub
Follow me on twitter: https://twitter.com/johnbina
Offline
Shark,
nice.
Mektub
Thanks. I made it out of realy banal reason. I use KDE and before KDE i used deja dup in XFCE. I like to have as little as possible gtk applications (nothing against them) in my system (yeah, i know. Totally stupid
and that was the motive behind the script. I know there is qt based back-up applications out there but i just don't like them. I could use only duplicity but back then it was just to complicated for me ![]()
So, laziness and some weird GTK contamination fear can produce new knowledge and creativity ![]()
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Offline
I use a free dropbox account to store all my dot-configs, /etc-configs and other backups, but I don't want to use the dropbox daemon or have any folders synched, and instead prefer to do it manually with two shell functions and the dropbox_uploader.sh script in my '~/.bin' dir:
drop() {
dropbox_uploader.sh -u <username> -p <password> -f $1 -d /Public -v
}
dget() {
curl -sO <url_to_dropbox_public_folder>/$1
}Then when i've e.g. has made some changes to .vimrc, i run
drop .vimrcand to get a new .vimrc(or overwrite the old):
dget .vimrcEdit: Ohh, I see there's a syntax change in newer versions, as I haden't updated in a while...
Last edited by mhertz (2012-09-09 21:45:56)
Offline
I use dropbox for storing some backups. This is a script i have made to fully automate it. I use gpg encryption of tar file too when uploading to dropbox.
You've actually inspired me to try this out for my own,
I always been bad at keeping backups of Configs I always mess around with. But now I can do it at a single command.
Steps:
Creates Folder and subFolders
Copies desired files and folders to the "Backup" dir
Creates Package and deletes "Backup" dir
Moves to Dropbox folder. ![]()
Keep in mind:
The Packages have the month and year on them. So if you update them within that same month the previous Package will be overwritten. I did this because I don't want too many back up folders.
#!/bin/bash
#ObliviousGmn
#Automate backup for dropbox w/ pretty colors
USECOLOR="yes"
. /etc/rc.d/functions
echo
stat_busy "Copying Configs"
mkdir Backups
mkdir Backups/Ncmpcpp
mkdir Backups/Weechat
cp .xinitrc Backups
cp .Xdefaults Backups
cp .bashrc Backups
cp .vimrc Backups
cp ~/.ncmpcpp/config Backups/Ncmpcpp/
cp ~/.weechat/weechat.conf Backups/Weechat/
cp ~/.weechat/irc.conf Backups/Weechat/
cp -ar ~/.config/luakit Backups
cp -ar ~/.config/openbox Backups
cp -ar ~/.config/ranger Backups
cp -ar ~/.config/tint2 Backups
cp -ar ~/Customize Backups
cp -ar ~/.themes/Gmnbox Backups
stat_done
stat_busy "Creating Backup Folder"
tar cf Backup_$(date +%m%Y).tar Backups;
stat_done
stat_busy "Sweeping up"
rm -rf Backups/
mv Backup_$(date +%m%Y).tar ~/.DropBox/Dropbox/;
stat_done
echoLast edited by ObliviousGmn (2012-09-02 19:49:51)
- The Github -
Offline
1. Makes a backup of your existing mirrorlist and updates it according to mirror status.
2. Needs reflector.
#!/bin/bash
#
# Script to optimize Archlinux mirrors by speed and sync status
# Author: Illusionist
#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
function progress {
chars=( "-" "\\" "|" "/" )
interval=0.2
count=0
while true
do
pos=$(($count % 4))
echo -en "\b${chars[$pos]}"
count=$(($count + 1))
sleep $interval
done
}
function stop_progress {
exec 2>/dev/null
kill $1
echo -en "\bdone!\n"
}
function halt_progress {
exec 2>/dev/null && cp /etc/pacman.d/mirrorlist.bak /etc/pacman.d/mirrorlist
kill $1
echo -e "\nTerminated by user\nRestored mirrorlist from backup\nFor more information visit: https://wiki.archlinux.org/index.php/Mirror"
}
echo -e "Backing up existing mirrorlist..."
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
echo -n "retrieving latest mirrorlist...."
progress &
pid=$!
trap 'halt_progress $pid; exit' 2
/usr/bin/reflector -l 10 --sort rate --save /etc/pacman.d/mirrorlist.temp
echo -ne "\bdone!\n"
echo -en "sorting mirrors by speed...."
rankmirrors -n 5 /etc/pacman.d/mirrorlist.temp > /etc/pacman.d/mirrorlist
stop_progress $pid
echo -e "\nFor more information visit: https://wiki.archlinux.org/index.php/Mirror"Last edited by illusionist (2012-12-03 20:41:34)
Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github
Offline