bash

How can I update Bugzilla bugs from bash and php scripts?

Our development process is highly automated via a raft of bash and php scripts (including subversion hook scripts.) These scripts do a number of things to integrate with our Bugzilla 3.0 installation. But the current integration approach is a bunch of SQL calls which update the bugzilla database directly - which obviously has a number ...

Reducing CPU processing time by using nice?

My hosting provider (pairNetworks) has certain rules for scripts run on the server. I'm trying to compress a file for backup purposes, and would ideally like to use bzip2 to take advantage of its AWESOME compression rate. However, when trying to compress this 90 MB file, the process sometimes runs upwards of 1.5 minutes. One of the resou...

PS1 line-wrapping with colours problem

Here's my PS1 variable: PS1='\u:\W$(__git_ps1 "\e[32m\][%s]\e[0m\]")$ ' Works great for picking up my Git branch, but it has the unfortunate side-effect of wrapping the lines when the colours are active, so that they overlap when you use long commands. Can anyone with magic PS1 skills help me out to fix this? ...

How do I get bash completion to work with aliases?

Case in point: I'm a on mac with bash v3.2.17, I'm using git installed via macports with the bash_completion variant. When I type git checkout m<tab>. for example, I get it completed to master. However, I've got an alias to git checkout, gco. When I type gco m<tab>, I don't get the branch name autocompleted. Ideally I'd like autocom...

How can you diff two pipelines in Bash?

How can you diff two pipelines without using temporary files in Bash? Say you have two command pipelines: foo | bar baz | quux And you want to find the diff in their outputs. One solution would obviously be to: foo | bar > /tmp/a baz | quux > /tmp/b diff /tmp/a /tmp/b Is it possible to do so without the use of temporary files in ...

parsing a line in bash

Hi could you please help me parse the following in bash. i have a file that has one entry per line, and each line has the following format. "group:permissions:users" where permissions and users could have more than one value separated by comas... like this "grp1:create,delete:yo,el,ella" what i want is to return the following ...

BASH while read loop breaking early

I've been banging my head against for wall for a while with this one. I want to SSH into a set of machines and check whether they are available (accepting connections and not being used). I have created a small script, tssh, which does just that: #!/bin/bash host=$1 timeout=${2:-1} ssh -qo "ConnectTimeout $timeout" $host "[ \`who | c...

writing bash script to change text and write to a log

I have written a very simple bash script to help me migrate from dev to staging. What it does is it deletes all files in staging, copies the files over from dev to stage. However, the config.inc.php file needs to have the first instance of "dev" to be changed to "stage", and no other instance changed. Second, everytime I run it (I run...

Bash string handling (char at index and concatenation)

I'm trying to learn bash string handling. How do I create a bash script which is equivalent to this Java code snippet? String symbols = "abcdefg12345_"; for (char i : symbols.toCharArray()) { for (char j : symbols.toCharArray()) { System.out.println(new StringBuffer().append(i).append(j)); } } The output of the above code...

sudo nohup nice <-- in what order?

So I have a script that I want to run as root, without hangup and nicely. What order should I put the commands in? sudo nohup nice foo.bash & or nohup nice sudo foo.bash & etc. I suspect it doesn't matter but would like some insight from those who really know. ...

Shell script numbering lines in a file

I need to find a faster way to number lines in a file in a specific way using tools like awk and sed. I need the first character on each line to be numbered in this fashion: 1,2,3,1,2,3,1,2,3 etc. For example, if the input was this: line 1 line 2 line 3 line 4 line 5 line 6 line 7 The output needs to look like this: 1line 1 2line 2...

How to add file extensions based on file type on Linux/Unix?

This is a question regarding Unix shell scripting (any shell), but any other "standard" scripting language solution would also be appreciated: I have a directory full of files where the filenames are hash values like this: fd73d0cf8ee68073dce270cf7e770b97 fec8047a9186fdcc98fdbfc0ea6075ee These files have different original file types...

using regex to find files with certain extensions

What's the regular expression I could use with find -regex to find all files that have a .xls or .csv extension? ...

How to wait in bash for several subprocesses to finish and return exit code !=0 when any subprocess ends with code !=0 ?

How to wait in a bash script for several subprocesses spawned from that script to finish and return exit code !=0 when any of the subprocesses ends with code !=0 ? Simple script: #!/bin/bash for i in `seq 0 9`; do doCalculations $i & done wait The above script will wait for all 10 spawned subprocesses, but it will always give exit ...

How to output MySQL query results in csv format?

Is there an easy way to run a MySQL query from the linux command line and output the results in csv format? Here's what I'm doing now: mysql -u uid -ppwd -D dbname << EOQ | sed -e 's/ /,/g' | tee list.csv select id, concat("\"",name,"\"") as name from students EOQ It gets messy when there are a lot of columns that need to be...

How can I reformat messages in an mbox file with bash or Perl?

Hello, I have a huge mbox file, with maybe 500 emails in it. It looks like the following: From [email protected] Fri Aug 12 09:34:09 2005 Message-ID: <[email protected]> Date: Fri, 12 Aug 2005 09:34:09 +0900 From: me <[email protected]> User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 ...

bash scripting..copying files without overwriting

Hello, I would like to know if it is possible to copy/move files to a destination based on the origin name. Basically, I have a /mail folder, which has several subfolders such as cur and new etc. I then have an extracted backup in /mail/home/username that is a duplicate. mv -f will not work, as I do not have permission to overwrite the...

How do I get both STDOUT and STDERR to go to the terminal and a log file?

I have a script which will be run interactively by non-technical users. The script writes status updates to STDOUT so that the user can be sure that the script is running OK. I want both STDOUT and STDERR redirected to the terminal (so that the user can see that the script is working as well as see if there was a problem). I also want b...

How can I reorder an mbox file chronologically?

Hello, I have a single spool mbox file that was created with evolution, containing a selection of emails that I wish to print. My problem is that the emails are not placed into the mbox file chronologically. I would like to know the best way to place order the files from first to last using bash, perl or python. I would like to oder by ...

Shell scripting: die on any error

Suppose a shell script (/bin/sh or /bin/bash) contained several commands. How can I cleanly make the script terminate if any of the commands has a failing exit status? Obviously, one can use if blocks and/or callbacks, but is there a cleaner, more concise way? Using && is not really an option either, because the commands can be long, ...