bash

bashdb: Can I examine the data flowing through a pipe?

I'm trying to debug a bash script that involves a command of the form: VAR=$(cmd1|cmd2|cmd3) I can debug it in bashdb, using the s command, which does something like this: bashdb(2): s 2: VAR=$(cmd1|cmd2|cmd3) cmd1 bashdb(3): s 2: VAR=$(cmd1|cmd2|cmd3) cmd2 i.e. it allows me to run the commands in the pipe one by one. Log...

How do I manage a Python based daemon on Linux?

I have a working Python based program that I want to run as a daemon. Currently I'm doing it in a very hackish manner of starting it in with screen-d -m name session and killing it with pkill -9 -f name. Eventually I'm doing to have to move this to the better system we use here (thus I'm not willing to modify the program) but in the int...

Bash/shell script - shell output redirection inside a function

function grabSourceFile { cd /tmp/lmpsource wget $1 > $LOG baseName=$(basename $1) tar -xvf $baseName > $LOG cd $baseName } When I call this function The captured output is not going to the log file. The output redirection works fine until I call the function. The $LOG variable is set at the top...

How can I write a here doc to a file in bash script?

How can I write a here document to a file in bash script? ...

How to declare and use boolean variables in shell script?

Title. The way I tried declaring a boolean variable is by: variable=$false variable=$true Is the syntax correct? Also, if I wanted to update that variable would I just do the same format? Finally, is the following the proper syntax for using boolean variables as expressions: if [ $variable ] if [ !$variable ] Thanks! Any help is...

Weird behaviour with optparse and bash tab completion

Hi I am building a script for users new to Linux, so please understand why I am asking this :) My script runs like this: python script.py -f filename.txt I am using the optparse module for this. However, I noticed the following when doing tab completion. The tab completion works when I do: python script.py <tab completion> # Tab c...

Escaping Problem in bash using isql

Hi there, I am currently working on a little backup script from some firebird databases and I've come up with a weird escaping problem that I don't seem to be able to solve. Here's the thing in my script I create a variable called sqllog in which I would like to put the output of a chain of commands, here it is. sqllog=`echo "SELECT * F...

bash getting a fd of a pipe

Hi, Why does the following not work? exec 3<|cat $0 The idea is to get file-descriptor (3) of a pipe (| cat $0). ...

Shell script for testing

I want a simple testing shell script that launches a program N times in parallel, and saves each different output to a different file. I have made a start that launches the program in parallel and saves the output, but how can I keep only the outputs that are different? Also how can I actually make the echo DONE! indicate the end? #!/bi...

Shell script to count files, then remove oldest files

I am new to shell scripting, so I need some help here. I have a directory that fills up with backups. If I have more than 10 backup files, I would like to remove the oldest files, so that the 10 newest backup files are the only ones that are left. So far, I know how to count the files, which seems easy enough, but how do I then remove...

bitwise XOR a string in Bash

Hi. I am trying to accomplish a work in Bash scripting. I have a string which i want to XOR with my key. #!/bin/sh PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH teststring="abcdefghijklmnopqr" Now how do i XOR the value of teststring and store it in a variable using bash? Any help will be appreciated. Basically i am trying to dup...

find: missing argument to -exec

Hello all, I was helped out today with a command, but it doesn't seem to be working. This is the command: find /home/me/download/ -type f -name "*.rm" -exec ffmpeg -i {} -sameq {}.mp3 && rm {}\; The shell returns find: missing argument to `-exec' What I am basically trying to do is go through a directory recursively (if it has oth...

How to run command in the background and notify me via email when done

Hello all, I have the following command which will take ages to run (couple of hours). I would like to make it a background process and for it to send me an email when its done. For the cherry on the top, any errors it encountered should write to a text file when an error has occurred? find . -type f -name "*.rm" -exec ./rm2mp3.sh \...

resizing images with imagemagick via shell script

Hi there, I don't really know that much about bash scripts OR imagemagick, but I am attempting to create a script in which you can give some sort of regexp matching pattern for a list of images and then process those into new files that have a given filename prefix. for example given the following dir listing: allfiles01.jpg allfil...

Numeric test when using the conditional operator

In bash, why doesn't this work: $ echo $((1 -gt 2 ? 3 : 4)) bash: 1 -gt 2 ? 3 : 4: syntax error in expression (error token is "2 ? 3 : 4") Neither does this: $ echo $(((1 -gt 2) ? 3 : 4)) bash: (1 -gt 2) ? 3 : 4: missing `)' (error token is "2) ? 3 : 4") ...

Upon USB insert, record unique identifer sting, format drive to FAT32 and copy a file. Bash or Python.

Hello, This is what I want to do, insert USB flash drive. mount it. record uniquie identifer string to a file. format the drive to FAT32. copy a text file to the drive. unmount it. remove the drive. 30 times The situation is this, I have bought 30 usb drives. I need to format each one to ensure they are clean, I need the unique str...

linux + find word in file under directory but quickly

I have the following command find /var -type f -exec grep "param1" {} \; -print With this command I can find the param1 string in any file under /var but the time that it take for this is very long. I need other possibility to find string in file but much more faster then my example THX yael ...

Bash script: specify bc output number format

Greetings! I uses bс to make some calculations in my script. For example: bc scale=6 1/2 .500000 For further usage in my script I need "0.500000" insted of ".500000". Could you help me please to configure bc output number format for my case? ...

cpio VS tar and cp

I just learned that cpio has three modes: copy-out, copy-in and pass-through. I was wondering what are the advantages and disadvantages of cpio under copy-out and copy-in modes over tar. When is it better to use cpio and when to use tar? Similar question for cpio under pass-through mode versus cp. Thanks and regards! ...

Bash: "xargs cat", adding newlines after each file

I'm using a few commands to cat a few files, like this: cat somefile | grep example | awk -F '"' '{ print $2 }' | xargs cat It nearly works, but my issue is that I'd like to add a newline after each file. Can this be done in a one liner? (surely I can create a new script or a function that does cat and then echo -n but I was wonder...