SEARCH

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

You are not logged in.

#26 2010-12-22 16:31:17

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: shell script bits & pieces thread

  12:59 ~
         $ dnp
[sudo] password for sector11: 
 {space here} <<<--- how silly  :D
[======DISK======] [=============NAME==============] [====SIZE====] [MAJ] [MIN]
[sda             ] [WDC WD2500AAJS-0               ] [   232.89 GB] [  8] [  0]
[sdb             ] [HM250HI                        ] [   232.89 GB] [  8] [ 16]

[=====DEVICE=====] [==FILESYS==] [======LABEL======] [====SIZE====] [MAJ] [MIN] 
[sda1            ] [ext3       ] [<unknown>        ] [    18.63 GB] [  8] [  1] 
[sda2            ] [ext3       ] [<unknown>        ] [    37.25 GB] [  8] [  2] 
[sda3            ] [swap       ] [<unknown>        ] [     1.96 GB] [  8] [  3] 
[sda5            ] [ext3       ] [<unknown>        ] [    57.74 GB] [  8] [  5] 
[sda6            ] [ext3       ] [<unknown>        ] [    57.74 GB] [  8] [  6] 
[sda7            ] [ext3       ] [<unknown>        ] [    59.56 GB] [  8] [  7] 
[sdb1            ] [ntfs       ] [<unknown>        ] [   232.88 GB] [  8] [ 17] 
========================>>> fsarchiver probe simple <<<========================
 
Press a key to continue

Offline

Be excellent to each other!

#27 2010-12-22 16:39:12

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

Re: shell script bits & pieces thread

In that case just remove the sudo from inside the script and run it like so:

#!/bin/sh
echo ' '
echo '========================>>> fsarchiver probe simple <<<========================'
fsarchiver probe simple
echo ' '
echo 'Press a key to continue'
read key
~ $ sudo test_script
Password: 
 
========================>>> fsarchiver probe simple <<<========================
[======DISK======] [=============NAME==============] [====SIZE====] [MAJ] [MIN]
[sda             ] [WDC WD800JB-22JJ               ] [    74.53 GB] [  8] [  0]
[sdb             ] [00BEVT-00A0RT0                 ] [   298.09 GB] [  8] [ 16]

[=====DEVICE=====] [==FILESYS==] [======LABEL======] [====SIZE====] [MAJ] [MIN] 
[sda1            ] [ntfs       ] [<unknown>        ] [    50.00 GB] [  8] [  1] 
[sda5            ] [ext2       ] [<unknown>        ] [   101.94 MB] [  8] [  5] 
[sda6            ] [swap       ] [<unknown>        ] [   258.83 MB] [  8] [  6] 
[sda7            ] [ext4       ] [<unknown>        ] [     6.00 GB] [  8] [  7] 
[sda8            ] [ext4       ] [<unknown>        ] [    18.18 GB] [  8] [  8] 
[sdb1            ] [ntfs       ] [Windows          ] [   149.05 GB] [  8] [ 17] 
[sdb2            ] [ext4       ] [Linux            ] [   149.04 GB] [  8] [ 18] 
 
Press a key to continue

Offline

#28 2010-12-22 16:50:32

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: shell script bits & pieces thread

Last edited by Sector11 (2010-12-22 16:54:23)

Offline

#29 2010-12-22 17:19:13

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: shell script bits & pieces thread

alias econky='gedit ~/Conky/OB_*'

Offline

#30 2010-12-23 15:24:58

mobilediesel
#! Member
Registered: 2010-08-19
Posts: 73

Re: shell script bits & pieces thread

I found the original code for this from somewhere I can't remember. I have modified it quite a bit to shorten it. If you use a "catch-all" download directory, this will help keep the drive from filling up. If 50% of the drive is free it will delete files from the download directory that are at least 365 days old. With less free space it deletes younger files. More than 50% free space it waits until the files are older. The idea is that if you haven't filed it away in a proper, permanent location you probably forgot about it and wont miss it when it's deleted. big_smile

#!/bin/bash
DOWNLOAD_DIR=$HOME/downloads
PARTITION=/dev/sda1 # set to the partition that has the download dir
DF=($(df -l | grep $PARTITION)) # assign Total, Used and Free space to an array
# ${DF[3]} is free space, ${DF[2]} is used space, ${DF[1]} is total size.
# $((${DF[3]}*365/${DF[2]})) gives the "grace" time.
find $DOWNLOAD_DIR -type f -atime +$((${DF[3]}*365/${DF[2]})) -exec rm {} \;
#remove Empty directories.
find $DOWNLOAD_DIR -type d -empty -print0 | xargs -0 rmdir

As already happens on this forum: correct, improve and update this code as you see the need!

Offline

#31 2010-12-23 15:28:55

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

Re: shell script bits & pieces thread

Offline

#32 2010-12-23 16:03:02

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: shell script bits & pieces thread

Offline

#33 2011-05-27 01:11:45

FlyHigh
#! Member
Registered: 2011-05-07
Posts: 51

Re: shell script bits & pieces thread

#!/bin/bash
echo "Scan Started"

search=$(ip route show | awk '(NR == 1) { print $1}') #store gateway/24 for whole network mapping to variable
        nmap -sP $search | grep 192 &> /tmp/hosts.txt #search for live hosts, displaying IP and dns name and write to file to avoid 255 lines showing up
        grep -v "ICMP" /tmp/hosts.txt # display all lines not containing "ICMP" (error lines, dead hosts)
        rm /tmp/hosts.txt # remove temporary file


echo
echo "Scan Finished "

Last edited by FlyHigh (2011-05-27 04:23:54)

Offline

#34 2011-05-27 02:25:15

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

Re: shell script bits & pieces thread

Last edited by anonymous (2011-05-27 02:25:56)

Offline

#35 2011-06-07 17:46:34

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

A couple of snippets using the mysterious "exec" command. (Well, maybe it's not mysterious to you...)

1) If you've got a script that needs to be run in a terminal, but maybe you'd like to just run it from Alt+F2 or even, if it's in your path, Alt+F3, or from another script without having to call up a terminal first...
Put this at the top of your script and it will check if it's running in a terminal, and if not call urxvt (or terminator or...) and run itself in the terminal:

 [ -t 1 ] && [ -t 0 ] || exec urxvt -e "$0" "$@"

2) When a script is running in the background its output usually goes to ~/.xsession-errors. If you want to have it sent somewhere else put in this line:

exec >>/path/to/logfile 2>&1

Everything after that point will be sent to logfile, including messages from apps the script has called. An example is in /etc/X11/Xsession on line 83 or so.

Offline

#36 2011-06-18 17:45:40

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

read

Offline

#37 2011-06-18 20:30:29

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: shell script bits & pieces thread

read

Last edited by Sector11 (2011-10-26 11:44:24)

Offline

#38 2011-10-01 18:01:16

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

...stuff...
some_tricky_command | notify-send "Tricky command's output" "$(cat)"
...more stuff...

Last edited by johnraff (2011-10-01 18:02:41)

Offline

#39 2011-10-25 08:28:18

Awebb
The Singularity
Registered: 2009-07-23
Posts: 2,812

Re: shell script bits & pieces thread

for i in `ps aux`; do touch $i; done

I'm so meta, even this acronym

Offline

#40 2011-10-26 05:53:01

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

^Awebb, is that 100% safe? For example 'ps aux | grep thunderbird' for me gives:
'john      2744  0.0  0.2   4760  1184 ?        S    13:39   0:00 /bin/bash /home/john/scripts/thunderbird.sh'
so /home/john/scripts/thunderbird.sh gets touched by your command (along with a lot of "permission denied" error messages referring to system files). No particular harm done in this case, but could it not be that a user might not want some personal executable touched like this?

Offline

#41 2011-12-09 02:47:50

aiBo
#! CrunchBanger
Registered: 2010-11-08
Posts: 243

Re: shell script bits & pieces thread

Sometimes I want to know the content of some environment variables.

/usr/bin/env

puts them all out, but it is looks a bit messy.

So I added some pipes, took out some uninteresting variables and apllied some colour.

function env() {
  exec /usr/bin/env "$@" | grep -v -e ^LESS_TERMCAP_ -e ^LS_COLORS | 
  column -t -s = | sed -e s/^/$'\e\[1;33m'/ -e s/\ /\&$'\e\[0;0m'/
}

The output looks like this: (imagine the first coloumn is in a nice, bold GREP-yellow)

aibo >>> env
TERM                rxvt-unicode-256color
SHELL               /bin/bash
HISTSIZE            10000
GTK2_RC_FILES       /home/aibo/.gtkrc-2.0
WINDOWID            27264175
TRASH               /home/aibo/.trash
USER                aibo
HISTFILESIZE        20000
...

Offline

#42 2011-12-09 09:25:06

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: shell script bits & pieces thread

nice, i usually use 'printenv', but it is messy in its output as well. this looks a lot better. good idea!

Offline

#43 2011-12-11 21:11:46

.not
#! Junkie
Registered: 2011-09-03
Posts: 340

Re: shell script bits & pieces thread

As I'm having problems with my fan (.. and therefore, the temperature of my device.) I often change the level of the fanspeed. I was enerved by always typing a - for myself - long command into my CLI, so I decided to turn it into a little 'script' (It's a oneliner basically ..).

#!/bin/bash
echo level $1 | sudo tee /proc/acpi/ibm/fan

(Requirements: echo, sudo, tee, fan_control=1 loaded with the kernel; Usage: scriptname $fanlevel)
Be warned, this may (!) harm your machine, so use it wisely.

Offline

#44 2011-12-12 11:10:11

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: shell script bits & pieces thread

Why not make it a function in your .bashrc ?

Offline

#45 2011-12-30 17:38:41

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

somecommand | command_that_cant_read_stdin /dev/stdin

Offline

#46 2011-12-30 20:43:13

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: shell script bits & pieces thread

^ cool, thanks for that, i had no idea!

Offline

#47 2011-12-30 22:28:45

mobilediesel
#! Member
Registered: 2010-08-19
Posts: 73

Re: shell script bits & pieces thread

somecommand | command_that_cant_read_stdin /dev/stdin

Offline

#48 2012-01-07 13:05:22

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: shell script bits & pieces thread

because i have finally figured out how to do this, i am posting this code-snippet here proudly:

#!/bin/bash
# iterate over an array continuously

myarray=(1 2 3 4)
MAXLEVEL=$(( ${#myarray[@]} - 1 ))
CEILING="n"
x=0
array_iterate() {
   while true; do
      echo "${myarray[$x]}"
      sleep 1
      
      if [[ $CEILING == "n" ]]; then
         x=$(( $x + 1 ))
         [ $x -lt $MAXLEVEL ] && CEILING="n" || CEILING="y"
      elif [[ $CEILING == "y" ]]; then
         x=$(( $x - 1 ))
         [ $x -eq 0 ] && CEILING="n" || CEILING="y"
      fi
   done
}
array_iterate

output: 1 2 3 4 3 2 1 2 3 4 3 2 1 2 3 4 3 2 1 (etc.)

Offline

#49 2012-01-07 16:36:24

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: shell script bits & pieces thread

^that's fun. What are you using it for?

I think you can cut out a couple of "CEILING=" statements where CEILING is already the value you're setting it to:

      if [[ $CEILING == "n" ]]; then
         x=$(( $x + 1 ))
         [ $x -lt $MAXLEVEL ] || CEILING="y"
      elif [[ $CEILING == "y" ]]; then
         x=$(( $x - 1 ))
         [ $x -eq 0 ] && CEILING="n"
      fi

Offline

Help fund CrunchBang, donate to the project!

#50 2012-01-07 16:49:39

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 13,970

Re: shell script bits & pieces thread

^ Looks like it might be helpful for a game of Up the River...I remember a couple times whwn everyone was too soused to remember down from up.

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.
Server: bleh

Debian Logo