bash

Line completion with custom commands

Hi, my Python program can be launched with a range of different options (or subcommands) like: $ myProgram doSomething $ myProgram doSomethingElse $ myProgram nowDoSomethingDifferent I want it to use auto-completion with so that if i type "myProgram d" it returns "myProgram doSomething" and if i type "myProgram n" it renders "myProgr...

How to extract a text part by regexp in linux shell?

How to extract a text part by regexp in linux shell? Lets say, I have file where in every line is an IP address, but in different position. What is the most simple way to extract those IP addresses using common unix command-line tools? ...

Extract substring in bash

Looking for a solution in bash (will be part of a script). Given a filename in the form "someletters_12345_moreleters.ext", I want to extract the 5 digits and put them into a variable. So to emphasize the point. I have a filename with x number of characters then a five digit sequence surrounded by a single underscore on either side th...

shell script templates

what would be your suggestions for a good bash/ksh script template to use as a standard for all newly created scripts? I usually start (after #! line) with a commented-out header with a filename, synopsis, usage, return values, author(s), changelog and would fit into 80-char lines. all documentation lines I start with double-hash symbo...

Execute several programs at the same time in an initialisation/bash script

Hello I am working with a simulator that uses rcS scripts to boot, this is my script cd /tests ./test1 & ./test2 & ./test3 & ./test4 exit What I want is run all the test at the same time and that the exit command is executed only when all the previous test have finished. And not only when test 4 has finished, is this possible?. Thank...

script to manipulate the dhcp/conf

i want to write a script to manipulate the dhcp.conf file. which in the sense, it has to read the file and it should ping all the lease IP and should give another text file, in which it should give the list of IPs, which devices are now existing. EDIT: thanks for your swift reply. dhcpd.conf file is like this lease 172.31.0.10 { some...

Updating live server from VCS

I run all my Django sites as SCGI daemons. I won't get into the fundamentals of why I do this but this means that when a site is running, there is a set of processes running from the following command: /websites/website-name/manage.py runfcgi method=threaded host=127.0.0.1 port=3036 protocol=scgi All is fine until I want to roll out a...

FTP not uploading last 4 bytes

I have a bash script to upload some files to my webserver. The problem is that it seems to assume that when they get to the webserver they are missing the final 4kb of the file. On my computer the file is listed as 8kb (rounded up because blocks are 4kb) yet only 4kb are uploaded. Here's the funny/confusing part, this only affects the ...

Whats the cmd/powershell equivalent of back tick on bash?

Redirecting command output: eg: echo "Foo `./print_5_As.rb`" would echo "Foo AAAAA" Thanks ...

Is there any trivial way to 'delete by date' using ´rm'- in bash?

I noticed today (after ~8 years of happily hacking away at bash) that there is no trivial way to 'delete by date' using ´rm'. The solution is therefore to pipe stuff around a combination of commands like rm, ls, find, awk and sed. Say for example I wanted to delete every file in the working directory from 2009, what would be a typical s...

What is the easiest way using common linux tools to check if a bunch of ip addresses belongs to given network?

What is the easiest way using common linux tools to check if a bunch of ip addresses belongs to given network? I just need a number of how many of given addresses belongs to given subnet. Lets say network is 192.16.55.40/27 and addresses is 192.16.55.45, 192.16.55.115, 88.87.45.8, 192.16.55.37, 192.16.55.60 and 192.16.55.210.. ...

cd doesn't work when redirecting output?

Here's a puzzler: can anyone explain why cd fails when the output is redirected to a pipe? E.g.: james@machine:~$ cd /tmp # fine, no problem james@machine:~$ cd /tmp | grep 'foo' # doesn't work james@machine:~$ cd /tmp | tee -a output.log # doesn't work james@machine:~$ cd /tmp >out.log ...

Bash text parsing golf

Hi, I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works: DEV='http://some/svn/server/' BRANCH='some/repos/branches/' LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r` LAST_UPDATE=${LAST_UPDATE:0:10} But ...

How to parse rss-feeds / xml in a shell script

Hi, I'd like to parse rss feeds and download podcasts on my ReadyNas which is running 24/7 anyway. So I'm thinking about having a shell script checking periodically the feeds and spawning wget to download the files. What is the best way to do the parsing? Thanks! ...

Temporary redirection of stderr in a bash script

Hello! I have a simple script which is used to start another program. This other program may sometimes yield a SIGSEGV, which disrupts my output. I have therefore added a couple of lines which is supposed to temporarily redirect the stderr to /dev/null such that the SIGSEGV is ignored. The following is a draft of my code: exec 2> /dev/...

Bash: How to feed a command with the multiple results generated by one subcommand

Hi, I want to process each source code file after it has been preprocessed: myprocess `gcc -E file1.c` myprocess `gcc -E file2.c` ... myprocess `gcc -E fileN.c` This gets tedious so how do I make this a single command? That is, something along the line: myprocess SOMETHINGMAGIC(gcc -E file*.c) Thanks in advance! ...

Access X11 display from empty environment (bash)

Greetings! I am implementing a backup solution, and I need to access the X11 display for getting a password from the user and displaying status information. I have tried setting $DISPLAY in the script to :0.0 (hardcoded), but xhost and misc complain that they cannot open the display. What should I do? PS: The script is here: http://dpa...

lambda functions in bash

Is there a way to implement/use lambda functions in bash? I'm thinking of something like: $ someCommand | xargs -L1 (lambda function) ...

Bash script to receive and repass quoted parameters

I'm trying to get quoted parameters of a bash script to safely be received by a nested script. Any ideas? test.sh #!/bin/bash echo $* bash myecho.sh $* myecho.sh #!/bin/bash echo $1 echo $2 echo $3 echo $4 Sample: bash test.sh aaa bbb '"ccc ddd"' Result: aaa bbb "ccc ddd" aaa bbb "ccc ddd" Wanted result aaa bbb "ccc ddd...

How to learn your way through Linux's shell

I want to stop losing precious time when dealing with linux/unix's shell. If I could get to understand it all so well, that would be so great. Otherwise: I may end up loosing a day just for setting up a crontab. I'll keep wondering why the shebang in this script doesn't work. I'll keep wondering what's the real difference between: . ...