bash

Wget creates output file even when page does not exist.

Hi, Is is possible to prevent Wget from making an output file when there is an error like 404. When I run wget -O my.html http://sdfsdfdsf.sdfds http://sdfsdfdsf.sdfds does not exist but Wget still creates my.html I am making a bash script and want to make sure it stops if wget can't get a valid file. ...

To bind clear to ^l in Bash

I would like to have Ctrl-l for clear in my Bash. How can you bind Ctrl-l to clear in Bash? ...

To understand Typeset for PythonPath

One recommends me the following code apparently only in .zshrc without explaining its purpose clearly. typeset -U PYTHONPATH I am interested in how you can use the code in .bashrc. My Bash goes upset about the command. How can you use the command in Bash? ...

Keeping a rake job running

Hi, I'm using delayed_job to run jobs, with new jobs being added every minute by a cronjob. Currently I have an issue where the rake jobs:work task, currently started with 'nohup rake jobs:work &' manually, is randomly exiting. While God seems to be a solution to some people, the extra memory overhead is rather annoying and I'd prefer...

Match folder name from url using regex

I want to match just the folder name that a file is in, eg: pic/2009/cat01.jpg pic/2009/01/cat02.jpg I want to just match what I put in bold. So far I have this: [^/]*/ Which will match, pic/2009/cat01.jpg Any idea? ...

Wait for bash background jobs in script to be finished

To maximize CPU usage (I run things on a Debian Lenny in EC2) I have a simple script to launch jobs in parallel: #!/bin/bash for i in apache-200901*.log; do echo "Processing $i ..."; do_something_important; done & for i in apache-200902*.log; do echo "Processing $i ..."; do_something_important; done & for i in apache-200903*.log; do ec...

Bash scripting: Find all filetypes and paths

Using Bash, how can you traverse folders within specified folder, find all files of specified file type, and every time you find a file, get full file path with file name and full file path without file name as a variables and pass them to another Bash script, execute it, and continue searching for the next file? ...

Is Perl faster than bash?

I have a bash script that cuts out a section of a logfile between 2 timestamps, but because of the size of the files, it takes quite a while to run. If I were to rewrite the script in Perl, could I achieve a significant speed increase - or would I have to move to something like C to accomplish this? #!/bin/bash if [ $# -ne 3 ]; then ...

Shell Prompt Line Wrapping Issue

I've done something to break my Bash Shell Prompt in OS X (10.5.7) Terminal. This is the PS1 that I had configured: PS1='\[\e[1;32m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ ' As far as I can tell I have the color commands escaping correctly. However when I scroll up and down in my command history I often get line wrapping issues if the...

Allowing user to configure cron

I have this bash script on the server that runs every hour, via cron. I was perfectly happy, but now the user wants to be able to configure the frequency through the web interface. I don't feel comfortable manipulating the cron configuration programmatically, but I'm not sure if the other options are any better. The way I see it, I can...

inotifywait command not detecting files but folders it does.

Im trying to use inotifywait to detect every time a file or folder gets moved into a folder in realtime (eg. /root in the case) I tried this, which does detect both folders and files, but this is for a created file, I want it for a moved file/folder. inotifywait --monitor --format %f --event create /root So then I use this, but using...

can xsltproc be used to parse non UTF 8 xml files

I have written a bash shell script that reads a directory and parses all the XML files in it in a for loop. I am taking each XML file and feeding it to xsltproc along with a xsl style sheet. The problem is some xml files are having non UTF 8 characters and the parser is unable to open those files. Parser error is thrown saying that UTF 8...

Find Active Directory users home folder from login hook script in OS X

I need to write a OS X login hook script that is aware of the users current home folder. Since the users are Active Directory users, their home folders are not stored in /Users so I can't simply hard code the full path. Since the login hook is run by a daemon as root, I can not use $HOME, ~, etc either. The only piece of info I have i...

Using a bash script on a Mac to connect to network shares?

I'm using a Mac at work and would like some network shares mounting when i start the computer. Can i use a bash script (or similar) to connect and mount these shares? The shares are from both Windows and Mac servers and we usually connect using IP addresses. ...

Delete a symbolic link when the original folder is deleted

I was thinking of using inotifywait to watch the original folder where the original folders are in, then when ever it detects that a folder has been deleted, then delete the same symbolic link in the other folder. So my question is, is that the best way? Or are there better ways to delete a symbolic link when the original folder gets de...

In a bash script/command how can I make a PC beep noise, or play a sound file?

I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input. I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker ...

Print last 10 rows of specific columns using awk

Hi, I have the below awk command-line argument and it works aside from the fact it performs the print argument on the entire file (as expected). I would like it to just perform the formatting on the last 10 lines of the file (or any arbitrary number). Any suggestions are greatly appreciated, thanks! I know one solution would be to ...

Properly handling spaces and quotes in bash completion

What is the correct/best way of handling spaces and quotes in bash completion? Here’s a simple example. I have a command called words (e.g., a dictionary lookup program) that takes various words as arguments. The supported ‘words’ may actually contain spaces, and are defined in a file called words.dat: foo bar one bar two Here’s my f...

How do a run a bash script on save in NetBeans?

Dear Gurus, I am using NetBeans 6.5 and whenever I save a LessCSS file I would like to run less compiler to compile it to native css. How do I go about achieving this? Many Thanks. Ravi EDIT: I can do a build file as Kim recommended below. I am searching for a solution where I can run an external command. So the question now is How Do ...

Run crontab with user input

Hi, i created a crontab which will run a bash script test.sh. This test.sh file requires some input from the user, and saves the user input into a variable. How do i ensure that the user input will be saved to a variable in test.sh, and when crontab runs the script i can get the output i want? for e.g i have 2 files, file1.sh and file2....