SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2010-06-22 19:30:43

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Bash Scripts - make crunching easier

Show us your useful bash scripts.  #! is know for having people that love the CLI.  So if you have a useful bash scripe that others might like why not share it.

These were created by anonymous and work well.

Search the CrunchBang forums with:

title (the script name)

title word 
#!/bin/bash
# by anonymous - crunchbang linux

q=$1
iceweasel "http://www.google.com/search?q=site:crunchbanglinux.org/forums/ intitle:$q"

or (the script name)

or word1 word2 
#!/bin/bash
# by anonymous - crunchbang linux

q=$1
r=$2
iceweasel "http://www.google.com/search?q=site:crunchbanglinux.org/forums/ intitle:$q OR intitle:$r"

sample of "or"
tNHIyag

and (the script name)

and word1 word2 
#!/bin/bash
# by anonymous - crunchbang linux

q=$1
r=$2
iceweasel "http://www.google.com/search?q=site:crunchbanglinux.org/forums/ intitle:$q AND intitle:$r"

I can't write scripts beyond the insanely simple stuff, I am learning a bit though and maybe these will help.

→↓→↓→↓ BASH Links ↓←↓←↓←

If you find a useful link pop it into a post and/or PM me with a link to it so I can add it here (in case I miss it.).

The big three, Beginners, Intermediate and Advanced Bash scripting:

Bash Guide for Beginners - Thanks winotree
So I thought - Intermediate? Intermediate Bash Tutorial - by jbsnake at of all places: BashScripts.org - I joined.  big_smile
Advanced Bash-Scripting Guide

Contributed links:

LinuxCommand.org - Thanks anonymous
BASH Frequently Asked Questions - Thanks anonymous
Alien's Bash Tutorial - Thanks anonymous

Stuff I found:

An A-Z Index of the Bash command line for Linux
A quick guide to writing scripts using the bash shell
Bash build script
Bash Prompt HOWTO
Bash Reference Manual
Bash scripting Tutorial
Bash Shell Scripting 10 Seconds Guide
Shell Programming
Very Simple Bash Scripts
Writing robust shell scripts

Last edited by Sector11 (2010-06-30 19:05:46)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

Be excellent to each other!

#2 2010-06-24 05:56:58

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

Might be overkill, but I hacked this together. Not exhaustively checked, so feel free to criticize/suggest...
(btw I think google searches are AND by default.)

#!/bin/bash
# search the Crunchbang forums

USAGE='USAGE:
search words  - search the forum with several words, other google stuff like OR also OK.
"search phrase" - search for fixed phrase
-t topic word - search for topic in title, word anywhere
-t "topic phrase" word - search for "topic phrase" in title, word anywhere
-t topic -t subject - search for topic AND subject in title
-h or --help - this message
etc...'

unset q
while [[ $1 ]]
do
    case $1 in
        -t) 
        shift
        if [[ $(echo $1 | wc -w) -eq 1 ]]
        then
            q="$q intitle:$1"
        else
            q="$q intitle:\"$1\""
        fi
        ;;
        
        -h|--help)
        echo "$USAGE"
        exit 0
        ;;
        
        *)
        if [[ $(echo $1 | wc -w) -eq 1 ]]
        then
            q="$q $1"
        else
            q="$q \"$1\""
        fi
        ;;
    esac
    shift
done

iceweasel "http://www.google.com/search?q=site:crunchbanglinux.org/forums/ $q"

exit 0

edit: Of course the two big advantages of using this script instead of just typing into the Google search box at the top of the page are:
1) You can type [scriptname -t "search phrase"] instead of [intitle:"search phrase"].
2) You get to type into a terminal.

big_smile

Last edited by johnraff (2010-06-24 17:15:36)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#3 2010-06-24 17:14:38

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

johnraff wrote:
Sector11 wrote:
johnraff wrote:

Posted a bloated version of Crunchbang search on Sector11's thread:
http://crunchbanglinux.org/forums/post/73953/#p73953

With all due respect, I started Bash Scripts - make crunching easier to (I'll look at yours a little later):

A - keep things on topic here, and
B - hopefully people will share various bash scripts that they find useful - like sharing conky files, tint2 configs etc etc. and we all can learn something.

...so I posted that script (incorporating some of the ideas that came up here) over there precisely because I thought it was a more appropriate place than an "XFCE forum?" thread, with the vague hope that this googly discussion might move over there too. If your intention was something different, apologies. smile

No, you got it right, I was trying to get the non-xfce talk away from the thread.

I appreciate very much your posting your work here, and if "I" offended you with my reply in the XFCE4 thread, please accept my apology.

Offending someone, anyone, is not something I want to do in anyway.


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#4 2010-06-24 17:27:58

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

No, no offence taken!

Anyway, sharing ideas and learning from each other is one of the things these forums are great for. smile


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#5 2010-06-24 17:38:33

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

...thinking, it would be nice if we could get Firefox/Iceweasel to tell us the title of the current page automatically, instead of having to type it in. The information is out there somewhere, because the window manager puts it in the top bar of the window. Does anyone know where it is?


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#6 2010-06-24 17:42:20

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

johnraff wrote:

edit: Of course the two big advantages of using this script instead of just typing into the Google search box at the top of the page are:
1) You can type [scriptname -t "search phrase"] instead of [intitle:"search phrase"].
2) You get to type into a terminal.

big_smile

Well, I just took ~/bin/cbs for a test run and it passed with flying colours!

I called it cbs for CrunchBangSearch.  It really is a slick script.

And I got to type in the terminal  big_smile  I also tried it with: [Alt]+[F2] - works just as well.

cbs sector11
cbs johnraff
cbs -t "bash" sector11

I do wish Google would stop with the:
Did you mean: site:crunchbanglinux.org/forums/ intitle:bash sector 11  -or-
Did you mean to search for: site:crunchbanglinux.org/forums/ intitle:bash sector 11

NO damn it, I am "sector11"

Some time I see stuff like: (eaxmple:  searching for for xyz)
Did you mean: xy and z
Showing results for xy and z
GRRRRRRR!!!!!

Thank you johnraff - nice script!

NEXT!  Yes, you, in the sunglasses! cool
Introduce yourself and show us your script.  And no muppet jokes either!

Last edited by Sector11 (2010-06-24 17:45:15)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#7 2010-06-24 17:56:32

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,156

Re: Bash Scripts - make crunching easier

johnraff wrote:

...thinking, it would be nice if we could get Firefox/Iceweasel to tell us the title of the current page automatically, instead of having to type it in. The information is out there somewhere, because the window manager puts it in the top bar of the window. Does anyone know where it is?

This may have changed, but in the old days (HTML 1.0) the page title was in metadata in the markup code.  For example, this page

<html>
<head><title>This is a sample page.</title></head>
<body>
<h1>Sample Page</h1>
The actual page contents goes in this section.
</body>
</html>

would have the title "This is a sample page."  I don't know if there's a way to get that displayed from the command line though.


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#8 2010-06-24 18:01:35

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

johnraff wrote:

No, no offence taken!

Then obviously I did not express my self right.  I meant ... OH! you said No offence taken, phew that was easy.  lol lol  I didn't think so but wanted to cover the bases anyway.

johnraff wrote:

Anyway, sharing ideas and learning from each other is one of the things these forums are great for. smile

I agree.

However the Iceweasel title is a bit more than needed I think:

Post new reply - Bash Scripts - make crunching easier - Tips, Tricks & Scripts - CrunchBang Linux Forums - Iceweasel

I would never type that in to the script to do a search, by the time I got it in, checked for spelling errors, then is two really two or is it to or too and checked some other stuff it would be dinner time.  big_smile


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#9 2010-06-24 18:07:36

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

pvsage wrote:

This may have changed, but in the old days (HTML 1.0) the page title was in metadata in the markup code.

That is still valid: [Ctrl]U or Iceweasel > View > Page Source:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="ROBOTS" content="NOINDEX, FOLLOW" />
<title>Post new reply - Bash Scripts - make crunching easier - Tips, Tricks &amp; Scripts - CrunchBang Linux Forums</title>
<link rel="top" href="http://crunchbanglinux.org/forums" title="Forum index" />
<link rel="up" href="http://crunchbanglinux.org/forums/topic/8288/bash-scripts-make-crunching-easier/" title="Bash Scripts - make crunching easier" />
<link rel="search" href="http://crunchbanglinux.org/forums/search/" title="Search" />
<link rel="author" href="http://crunchbanglinux.org/forums/users/" title="User list" />

I use [Ctrl]U a LOT!

Last edited by Sector11 (2010-06-24 18:08:15)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#10 2010-06-25 16:26:09

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

pvsage wrote:
johnraff wrote:

...thinking, it would be nice if we could get Firefox/Iceweasel to tell us the title of the current page automatically, instead of having to type it in. The information is out there somewhere, because the window manager puts it in the top bar of the window. Does anyone know where it is?

This may have changed, but in the old days (HTML 1.0) the page title was in metadata in the markup code.~~I don't know if there's a way to get that displayed from the command line though.

Yes the title's in the html, but I don't know if a script running outside firefox would have any way of getting that html code, short of downloading the page again with wget, curl or one of the cli browsers, which would require getting the url of the current page from firefox...

What I was wondering was whether there was some "x" "window" type command which could access the string to go in the title of the window; since the window manager obviously is in on it, why can't we be too? Then you could do a "search this thread" type command and the script would already know what to put in the "intitle:..." bit. cool

Sector11 wrote:

However the Iceweasel title is a bit more than needed I think:

Post new reply - Bash Scripts - make crunching easier - Tips, Tricks & Scripts - CrunchBang Linux Forums - Iceweasel

I would never type that in to the script to do a search, by the time I got it in, checked for spelling errors, then is two really two or is it to or too and checked some other stuff it would be dinner time.

Agreed, if you had to type it in yourself, but if it went in automatically it would be OK, right?


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#11 2010-06-25 17:47:23

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

johnraff wrote:
Sector11 wrote:

However the Iceweasel title is a bit more than needed I think:

Post new reply - Bash Scripts - make crunching easier - Tips, Tricks & Scripts - CrunchBang Linux Forums - Iceweasel

I would never type that in to the script to do a search, by the time I got it in, checked for spelling errors, then is two really two or is it to or too and checked some other stuff it would be dinner time.

Agreed, if you had to type it in yourself, but if it went in automatically it would be OK, right?

The problem as I see it, you would not have that information until after the search as you said.  BUT, yes you are right, it would be nice.

It is not an impossible problem, it involves a computer, one just needs to find the way to do it.

Last edited by Sector11 (2010-06-25 18:14:13)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#12 2010-06-25 18:01:38

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

PLEASE NOTE:  This is a joke and partly historical in content.  It is NOT meant to be taken seriously!  And for obvious reasons the content of the autoexec.bat file is not displayed here.

I found this thread and though of the old DOS "autoexec.bat" file joke that early versions of Windows still used.  WAY before there was any problems like we have today.

-------------------
Your much hated boss is going to X country for a conference.  You grab his laptop and rewrite the autoexec batch file to display a countdown from 60 seconds:

Detonation in:
     60
   seconds

and hope security at the airport asks him to fire up his laptop.
-------------------
to continue...
So I see that other thread and think as a learning thing luxwin and winlux both in ~/bin, both executable...

luxwin

#!/bin/bash
terminator -e winlux
exit

and winlux

#!/bin/bash
echo "Removing Linux -"
echo "Working ."
sleep 1s
echo "Still Working ....."
sleep 1s
echo "Still Working"
sleep 1s
echo "Still Work ... ERROR ..."
sleep 1s
echo "Done"
echo " "
echo "Re-installing Windows 7"
echo "Go get a coffee you have time."
sleep 3s
echo "ERROR - Windows error 255443.877"
echo "failed to overwrite GRUB"
sleep 1s
echo "Re-initalizing Linux"
sleep 3s
echo "Done"
echo " "
echo "Sending 'Failure to Up-date' email to Microsoft"
echo " "
echo "You will be contacted shortly"
sleep 5s
echo "Email sent"
sleep 1s
echo "Attempting to Reboot the Linux System"
sleep 3s
exit

[Alt]+[F2]+luxwin

mind is churning away here...

tNHIwdQ

Last edited by Sector11 (2010-06-25 18:15:04)


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#13 2010-06-25 18:19:39

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

(ducks to avoid flying debris)

Re that window title stuff, it looks as if the information might be got from something called 'xprop', if you know how to ask it nicely. This needs a bit (lot) more rtfm...


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#14 2010-06-25 18:39:18

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,156

Re: Bash Scripts - make crunching easier

^ NICE!!!

Now we just need to figure out how to remove everything from "(Page n)" onward.  Sounds like a job for sed or awk?  (We're just searching for the forum title itself, which is everything *before* the page number, in this case 'Bash Scripts - make crunching easier'.)


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#15 2010-06-25 18:40:28

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 9,418

Re: Bash Scripts - make crunching easier

You can use this command to get the title of a window:

xprop WM_NAME | cut -d\" -f2

However after running the command you have to click on the window you want so its not really automatic.

Offline

#16 2010-06-25 18:59:24

winotree
#! Die Hard
Registered: 2010-03-26
Posts: 548

Re: Bash Scripts - make crunching easier

Youse guys look to be having a real blast -- but it's all going over my head.  roll  So I did a little Google using bash scripting for beginners as search terms and came up with this http://tldp.org/LDP/Bash-Beginners-Guide/html/ which I'll try to come to grips with over the weekend.  Thought to add the link in case someone else wanted it.  smile

Offline

#17 2010-06-25 19:19:28

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 9,418

Re: Bash Scripts - make crunching easier

Offline

#18 2010-06-25 19:33:49

winotree
#! Die Hard
Registered: 2010-03-26
Posts: 548

Re: Bash Scripts - make crunching easier

You're good!  big_smile

Offline

#19 2010-06-25 19:51:10

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

johnraff wrote:

(ducks to avoid flying debris)

I N C O M I N G !!!!! Everyone down!!!
Us sector 9 escapees know how to do that right!

johnraff wrote:

This needs a bit (lot) more rtfm...

Yes I thought the same: Read The Full Manual  lol

pvsage wrote:

^ NICE!!!

Sounds like a job for sed or awk?

Can they be combined to be: sawk?
(ducks to avoid flying debris)

This is where I get REALLY lost with bash scripts - when you start including other commands.  Now reading man pages is fine but sometimes they can be as confusing as hexadecimal numbers in a binary world. And then using sed and awk on one line ... dizzy!!!!

@ winotree & anonymous

Thanks for the links - I am almost illiterate when it comes to bash, but I can copy one and make simple edits to be functional here on my computer.


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#20 2010-06-25 19:53:58

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

winotree wrote:

Youse guys look to be having a real blast -- but it's all going over my head.

shhhhhhhhh we be two peas in the same pod, but do not tell anyone


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#21 2010-06-25 20:26:32

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 11,415
Website

Re: Bash Scripts - make crunching easier

anonymous wrote:

You can use this command to get the title of a window:

xprop WM_NAME | cut -d\" -f2

However after running the command you have to click on the window you want so its not really automatic.

I am at a loss here - just where would I run that command?


To #! or not to #! that is the question!
#! Conky = 13 Threads & the Conky Archives | Conky PitStop | OHCG'er
#! Forum Moderator   |   StartPage -  protect your privacy   |   BBQ Linux

Offline

#22 2010-06-25 20:54:31

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 9,418

Re: Bash Scripts - make crunching easier

A terminal.

Offline

#23 2010-06-26 05:19:23

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,847
Website

Re: Bash Scripts - make crunching easier

pvsage wrote:

Now we just need to figure out how to remove everything from "(Page n)" onward.  Sounds like a job for sed or awk?  (We're just searching for the forum title itself, which is everything *before* the page number, in this case 'Bash Scripts - make crunching easier'.)

That bit can be done with bash's built-in parameter expansion.

title="some title name (Page 1) other stuff"
echo "${title%%(Page*}"

returns everything up to the "(Page..." bit.

anonymous wrote:

You can use this command to get the title of a window:

xprop WM_NAME | cut -d\" -f2

However after running the command you have to click on the window you want so its not really automatic.

Right. I was hoping to find a way of identifying the window without clicking on it. Maybe some way of connecting the PID from 'pidof iceweasel' to the X window id or window name. It should be possible... roll


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#24 2010-06-26 05:38:00

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 12,156

Re: Bash Scripts - make crunching easier

@johnraff:  You're gooood.  Tha's the kinda thing you jus' canna Google. cool


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

Help fund CrunchBang, donate to the project!

#25 2010-06-26 16:14:41

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 9,418

Re: Bash Scripts - make crunching easier

Ok I got it:

wmctrl -l | grep Namoroka | cut -c29- | sed s/" - Namoroka"//

Instead of Namoroka, put Iceweasel and you will have to adjust the number 29 so it cuts out the window id and host name from "wmctrl -l | grep Namoroka".

screenshot-1277568872.png

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo