You are not logged in.
@notbird:
alias please="sudo"
i like that
It makes for some fun 'conversations':
$ apt-get install firefox
Permission denied, are you root?
$ please !!
haha
Offline
^ Cute!
Make me a sandwich.
What? Make it yourself!
Please make me a sandwich?
OK.
Offline
OK Long script here, but it is one I built up myself over alot of years, there have been several contributors from people I know, I left them out to protect the guilty.
The script basically waits for input, any input it gets gets a datetime-stamp on the entry. Good for tracking just what the hell you were doing or writing about or thinking, I think of it as the captains log from star trek:
#!/bin/bash
function TITLEBLOCK ()
{
cat << EOF
#===============================================================================
#st
#
# FILE: eidetic.sh
#
# USAGE: ./eidetic.sh {-L, -s, -v, -h, --version}
#
# DESCRIPTION: This little program is just a simple Journal;
# an account of daily transactions and events
# ala Captain's log from Star Trek.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# AUTHOR: griffen76
# COMPANY: company withheld to protect me
# VERSION: 3.12
# CREATED: 10/07/2005 12:15:38 PM EDT
# REVISION: 06/10/2012
# Contributors: names with held to protect the guilty
#===============================================================================
EOF
} #end of TITLEBLOCK
##############
printIT ()
##############
{
MIN_PARAMS=1
ERRFLAG=${ERRFLAG:-98};[ $# -ge $MIN_PARAMS ] || doEXIT "Bad params [$FUNCNAME]"
# If not defined elsewhere - define it here
if [ "x$LOG_FLAG" = "xYES" ]; then
# This will allow you to add a time stamped log entry
# Expects a string messages as the parameter
# This strips off the colors before adding to the log...
echo "`date +%Y%m%d-%H:%M` - $@" \
>>$LOG_FILE
fi
echo "$@"
} #end of printIT
##########
doUSAGE ()
##########
{
cat << EOF
Usage: `basename $0` [$PARAMS]
-L Commence to loggin
-s Status
-v Read log file in entirety
-h Will show this usage info...
--version Will show version info and title block
EOF
export ERRFLAG=3
} # end of doUSAGE
#################
doEXIT ()
#################
{
#
ERRFLAG=${ERRFLAG:-"1000"}
EXIT_MSG=${EXIT_MSG:-"YES"}
# if we have params then print them
[ $# -gt 0 ] && printIT $@
# Now exit with appropriate msgs unless EXIT_MSG != YES
if [ "$ERRFLAG" = "0" ]; then
if [ "x$EXIT_MSG" = "xYES" ]; then
echo "${GREEN}Success${NORMAL}: `basename $0` $OPTION script exiting..."
echo Done... ${BRIGHT}Enjoy${NORMAL}!
fi
exit $ERRFLAG
else
if [ "$ERRFLAG" = "1000" ]; then
echo "Make sure you change the ERRFLAG in the script!"
fi
if [ "x$EXIT_MSG" = "xYES" ]; then
echo "${RED}WARNING${NORMAL}: Error ${RED}$ERRFLAG${NORMAL}"
echo Now exiting...
fi
exit $ERRFLAG
fi
} # end of doEXIT ()
#####
function CHECK_DATE ()
#####
{
LOG_THINKS=$(grep $(date +%Y) $LOG | wc -l)
#DAY_O_MONTH=$(date +%d)
DAY_O_MONTH=$(date +%j | sed -e s/^0//g | sed -e s/^0//g )
let START_DAY_LOG="$DAY_O_MONTH"-"$LOG_THINKS"-1
while test "$START_DAY_LOG" -ge 0
do
echo $(date --date="$START_DAY_LOG days ago" +%Y%m%d_%A) >> $LOG
let START_DAY_LOG=$START_DAY_LOG-1
done
} # end of CHECK_DATE
#####
function STATUS ()
#####
{
#=== FUNCTION ================================================================
# NAME: Status
# DESCRIPTION: Allows the reporting of items stored in the log file in a defined range.
# PARAMETERS: ---
# RETURNS: A report of items in a specified range
#===============================================================================
#####
function TIME_PERIOD ()
#####
{
#=== FUNCTION ================================================================
# NAME: TIME_PERIOD
# DESCRIPTION: Resides insde of function STATUS
# PARAMETERS: ----
# RETURNS: Days or weeks
#===============================================================================
CHECK_DATE
echo "days or weeks"
read case;
case $case in
days ) PERIOD="days";;
weeks ) PERIOD="weeks";;
*)
ERRFLAG="66"
LOG_FLAG="YES"
printIT Please try again. Only days or weeks are valid, you entered $case
TIME_PERIOD
;;
esac
UNIT_FOR_TIME
} # ---------- end of function TIME_PERIOD ----------
#####
function UNIT_FOR_TIME()
#####
{
#=== FUNCTION ================================================================
# NAME: UNIT_FOR_TIME
# DESCRIPTION: ----
# PARAMETERS: ----
# RETURNS: Asks the user to input the number of days/weeks
#===============================================================================
echo "How many? 1 2 3 4 5....."
read case;
case $case in
1) UNITS=1;;
2) UNITS=2;;
3) UNITS=3;;
4) UNITS=4;;
5) UNITS=5;;
6) UNITS=6;;
7) UNITS=7;;
*)
ERRFLAG="66"
LOG_FLAG="YES"
printIT A number between 1 and 7 was not entered $case was entered
UNIT_FOR_TIME
;;
esac
DATE_5=$(date --date="$UNITS $PERIOD ago" +%Y%m%d_%A)
DAY_1=$(grep -n $DATE_5 $LOG | awk 'BEGIN {FS = ":"} ; {print $1}')
DAYS_7=$(echo $[$DAY_2-$DAY_1+1])
head -n $DAY_2 $LOG | tail -n $DAYS_7
doEXIT
} # ---------- end of function UNIT_FOR_TIME ----------
TIME_PERIOD
} # ---------- end of function Status ----------
function LOGGING ()
{
#=== FUNCTION ================================================================
# NAME: LOGGING
# DESCRIPTION: Main otpion of eidetic.sh
# PARAMETERS: NONE
# RETURNS: A timestamped entry into specifyed LOG
#===============================================================================
#####Notice to the user the program has started
echo "Starting log."
#####Check to see if the date is already in the log file.
CHECK_DATE
#####Get the meat of the entries
echo "Welcome to" $USER $DATE_2
echo $EXITMESSAGE
echo -e $MESSAGE
read ENTRY
while [ "$ENTRY" != END ]
do
CHECK_DATE
DATE_4=$(date +%H:%M:%S)
echo -e '\t' $DATE_4 -- $ENTRY >> $LOG
echo -e $MESSAGE "Remember" $USER $EXITMESSAGE
read ENTRY
done
clear
ERRFLAG=0
doEXIT
} # ---------- end of function LOGGING ----------
function READ_LOG ()
{
#=== FUNCTION ================================================================
# NAME: READ_LOG
# DESCRIPTION: Read the actual log file with out changing it.
# PARAMETERS: NONE
# RETURNS: A view of the log file
#===============================================================================
CHECK_DATE
view $LOG
} # ---------- end of function READ_LOG ----------
#-------------------------------------------------------------------------------
# VARIBLES
#-------------------------------------------------------------------------------
LOG=/home/$USER/.eidetic.$USER
MESSAGE="What is your entry?"
EXITMESSAGE="type 'END' to end session"
LOG_FILE=/home/$USER/.log.eidetic.ERRORS
DATE_2=$(date +%Y%m%d_%A)
DAY_2=$(wc -l $LOG | awk 'BEGIN {FS = " "} ; {print $1}')
OPTION=$1
#-------------------------------------------------------------------------------
# Main Code
#-------------------------------------------------------------------------------
BASENAME=`basename $0`
if pidof -x $BASENAME > /dev/null; then
for p in $(pidof -x $(basename $0)); do
if [ $p -ne $$ ]; then #Checks to see if the pid of this process matches the pid running if no then it kicks us out.
echo "Script $0 is already running: exiting"
exit
fi
done
fi
ERRFLAG=0
PARAMS="L:s:h:v:version"
case $1 in
-L )
LOGGING # Calling Function LOGGING
ERRFLAG=0
doEXIT
;;
-s )
STATUS # Calling Function STATUS
ERRFLAG=0
doEXIT
;;
-h )
doUSAGE
;;
-v )
READ_LOG
;;
--version )
TITLEBLOCK
;;
* )
doUSAGE
doEXIT
;;
esac
Output:
$ eidetic.sh -s
days or weeks
days
How many? 1 2 3 4 5.....
2
20120608_Friday
20120609_Saturday
20120610_Sunday
13:29:47 -- Installed this script on the latest computer
13:30:24 -- Also uploaded this to the #! forums
13:41:02 -- installed libwww-perl and libjson-perl to get API working on wunderground.com based on the Practical Perl tools from ;login June 2012
Success: eidetic.sh -s script exiting...
Done... Enjoy!
Last edited by griffen76 (2012-06-10 17:43:28)
Offline
A neat little Perl script for listing files in the Dir and Subs from smallest to largest with a little Asterick graph
du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}'
Last edited by sqlpython (2012-06-10 18:33:04)
OHCG #!, Jessie,, Siduction-13.1, Slackware 14, Bridge,, Sabayon 13.4,
Offline
#!/bin/bash
case "$1" in
""|--help|-h)
printf "Ask google in your default XDG browser.\nUsage: google [query]\ngoogle --help,-h: This help.\nUse quotes for multiple words."
;;
*)
xdg-open "https://www.google.de/#hl=de&safe=off&output=search&q=$1"
;;
esac
Weeeelll... it's trivial, but hey, it came to this world after a cocktail night in my favourite bar
I'm so meta, even this acronym
Offline
Awebb, allow me to steal yours and modify it slightly to query translate.google.com (EN->DE)
#!/bin/bash
case "$1" in
""|--help|-h)
printf "Translate (English to German) with google in your default XDG browser.\nUsage: google [query]\ngoogle --help,-h: This help.\nUse quotes for multiple w$
;;
*)
xdg-open "http://translate.google.com/#en/de/$1"
;;
esac
Sweaty lads picking up the soap | I love the new "Ignore user" button
Offline
It's basically a showcase for using xdg-open in a script. You can even pass output to it with a pipe and xargs. I'm not too fond of reading from STDOUT in bash, so xargs is a must.
I'm so meta, even this acronym
Offline
I'm not too fond of reading from STDOUT in bash, so xargs is a must.
Hmm.. OK so what's wrong with reading from stdout?
...and what's so great about xargs? Seems a bit hacky to me. Handy for something quick in a terminal, but there's usually another way.
Last edited by johnraff (2012-08-07 15:39:00)
John
--------------------
( a boring Japan blog , Japan Links, idle twitterings and GitStuff )
#! forum moderator BunsenLabs
Offline
wget -q -O- "[url]http://rss.allrecipes.com/daily.aspx?hubID=80[/url]" | grep '<title>' | sed 's/<title>//g' | sed 's/<\/title>//g' | sed 's/Allrecipes Logo//g'
Machinebacon, what does -O- do?
sed 's/stress/relaxation/g'
Privacy & Security on #!
Offline
Tuna, -O- prints directly to standard output (the second - is stdout). You could also direct into a file first (use -O) :
wget -q -O tuna.txt "http://rss.allrecipes.com/daily.aspx?hubID=80"
cat tuna.txt | grep '<title>' | sed 's/<title>//g' | sed 's/<\/title>//g' | sed 's/Allrecipes Logo//g'
Last edited by machinebacon (2012-08-08 20:38:34)
Sweaty lads picking up the soap | I love the new "Ignore user" button
Offline
Tuna, -O- prints directly to standard output (the second - is stdout).
Thanks, couldn't find it in the man pages.
sed 's/stress/relaxation/g'
Privacy & Security on #!
Offline
Awebb wrote:I'm not too fond of reading from STDOUT in bash, so xargs is a must.
Hmm.. OK so what's wrong with reading from stdout?
...and what's so great about xargs? Seems a bit hacky to me. Handy for something quick in a terminal, but there's usually another way.
Take my script and and echo "beer" | thatscript. It won't work, because it does not produce an argument that can be passed as $1. You need xargs, to create an argument. I am not too fond, as I said, because, well, I don't know how :-D
I'm so meta, even this acronym
Offline
cat <filelocation>/<filename> | curl -F 'sprunge=<-' http://sprunge.us
great way to let others see files (configs etc) (no pictures though)
As a programmer i often ask myself could i get out of taking spanish in school because i know two languages Python and lua
Offline
Ever monitor disk read/writes with conky and wonder wtf is writing to your disk? Check out pidstat. I'm probably going to work this into conky somehow at some point.
Last edited by mynis01 (2012-08-22 13:07:48)
Offline
^ Or use iotop, from package of the same name:
sudo iotop -d 2 -o
bootinfoscript - emacs primer - wireless problems- I ♥ #!
Offline
Or you could use ${top_io} in conky.
top_io type num Same as top, except sorted by the amount of I/O the process has done during the update interval
Offline
@awebb Getting stdin into a script:
*) some commands will take stdin no problem, eg cat, sed, awk or read:
read -t 1 input1 input2
will read two words from stdin or exit with error after 1 second, so you can do
read -t 1 input1 input2
[[ $input1 ]] || get_input_some_other_way
*) /dev/stdin is a file, so access it as you would a file. In your script
$query="$( < /dev/stdin )"
might work.
eg this works
cat /etc/init.d/* | leafpad /dev/stdin
to see all the init.d files at once.
-------------------------------------------------
@anyone
comm: a handy utility for comparing two lists. (see man comm)
NB the two lists have to be sorted, so you often have to pipe some output to sort and do a process substitution:
comm <( do_something | sort ) <( do_something_else | sort )
Last edited by johnraff (2012-08-23 04:10:15)
John
--------------------
( a boring Japan blog , Japan Links, idle twitterings and GitStuff )
#! forum moderator BunsenLabs
Offline
Post to tumblr with vim, bash and curl:
#!/bin/bash
# post to tumblr from bash cli with curl
# change these to your relevant data:
username=USERNAME
email=EMAIL
password=PASSWORD
#create a distinct file name for the post with date.
filedate=$(date +%m%d%y%H%M%S)
read -p "Enter a post title: " ttitle
vim $filedate.tpost
read -p "Enter tags: " ttags
pbody="$(cat $filedate.tpost)"
login=$(curl -u $username:$password -d "email=$email" http://www.tumblr.com/api/authenticate)
if [[ $(curl -s -d "email=$email&password=$password&type=regular&generator=tumble.sh&title=$ttitle&tags=$ttags&body=$pbody" http://www.tumblr.com/api/write | grep error) ]]; then
echo "failure...not tumbled"
else
echo "Yeah! Tumbled!"
fi
mv $(pwd)/$filedate.tpost ~/Documents/fposts/ # just keeps posts archived in a subdir of ~/Documents/
read -p "Shall we have a look? (y or n): " browse
if [ $browse = y ];
then
xdg-open http://USERNAME.tumblr.com
fi
exit
this and more at http://tonyb.us/hax
Last edited by tonybaldwin (2012-08-28 01:35:31)
http://tonybaldwin.me
all tony, all the time
Offline
Not my own, bloom (I think he's registered here as baskerville) posted it on the arch-forums.
It takes a file as an argument and uploads it to ompldr.org, then prints the url + bbcodes to stdout and puts the latter in your clipboard. (It even has a nice progress-bar!)
If you run bash, simply change the shebang, it works.
#! /bin/dash
bbcodes=$(mktemp)
tmpout=$(mktemp)
while [ $# -gt 0 ] ; do
if [ -t 1 ] ; then
printf '%s \033[1;36m%s\033[0m\n' "Chomping" "$1"
else
echo "Chomping $1"
fi
curl -# -F "file1=@$1" http://ompldr.org/upload -o "$tmpout"
if [ $? -eq 0 ] ; then
awk '/BBCode:/ { gsub(/<[^<]*?\/?>/, ""); $1=$1; sub(/^[^:]*:/, ""); print }' "$tmpout" >> "$bbcodes"
if [ -t 1 ] ; then
awk '/Info:|File:|Thumbnail:|BBCode:/ { gsub(/<[^<]*?\/?>/, ""); $1=$1; sub(/^/, "\033[1;30m"); sub(/:/, "\033[0m: "); print }' "$tmpout"
else
awk '/Info:|File:|Thumbnail:|BBCode:/ { gsub(/<[^<]*?\/?>/, ""); $1=$1; sub(/:/, ": "); print }' "$tmpout"
fi
fi
shift
done
if [ -s "$bbcodes" ] ; then
cat "$bbcodes" | xsel -bi
fi
rm "$tmpout" "$bbcodes"
“From each according to his faculties; to each according to his needs”
Look at the code. Look at the silly code!
Offline
Here is what I use, very simple, nothing fancy:
#!/bin/bash
WALLPAPERS="/home/iann/downloads/wallpaper"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
feh --bg-scale $WALLPAPERS/${ALIST[$number]}
It uses feh to set the wallpaper, since I have that installed anyway, but you could change it to nitrogen.
Offline
#!/bin/bash
echo "Please don't necro post"
EOF
Offline
^ I dislike necro posts as much as the next guy (maybe more) but I don't really think posting a new script in a script thread qualifies. There is really no dated information in this thread, and iann just added his own script.
Offline
here is one called "where is my Nvidia?"
#!/bin/bash
# whereismyNvidia
echo "---------------------------"
echo "xorg.conf"
echo "---------------------------"
cat /etc/X11/xorg.conf
echo "---------------------------"
echo "lspci | grep VGA"
echo "---------------------------"
lspci | grep VGA
echo "---------------------------"
echo "dmesg | tail -30"
echo "---------------------------"
dmesg | tail -30
echo "---------------------------"
echo "lsmod | grep nvidia"
echo "---------------------------"
lsmod | grep nvidia
echo "---------------------------"
echo "modinfo nvidia"
echo "---------------------------"
modinfo nvidia
Offline
I posted in the wrong thread anyway. So now I'm going to get in trouble for double-posting
Offline
@pids. I would have preferred to see the script in a new thread that referenced this one. I agree, though, bash is never deprecated.
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat