bash

Why does using set -e cause my script to fail when called in crontab?

I have a bash script that performs several file operations. When any user runs this script, it executes successfully and outputs a few lines of text but when I try to cron it there are problems. It seems to run (I see an entry in cron log showing it was kicked off) but nothing happens, it doesn't output anything and doesn't do any of its...

Automatic exit from bash shell script on error

Hi, I've been writing some shell script and I would find it useful if there was the ability to halt the execution of said shell script if any of the commands failed. See below for an example: #!/bin/bash cd some_dir ./configure --some-flags make make install So in this case if the script can't change to the indicated dire...

bash string replacing a some char with another

folks, i have a string like AxxBCyyyDEFzzLMN I want to replace all x and y and z with _ so that the output is A_BC_DEF_LMN How to do that? I know a series of echo "$string" | tr 'x' '_' | tr 'y' '_' will work, but I want to do taht in one go, without using pipes EDIT: The following worked echo "$string" | tr '[xyz]' '_' ...

Write STDOUT & STDERR to a logfile, also write STDERR to screen

I would like to run several commands, and capture all output to a logfile. I also want to print any errors to the screen (or optionally mail the output to someone). Here's an example. The following command will run three commands, and will write all output (STDOUT and STDERR) into a single logfile. { command1 && command2 && command3 ; ...

Is there any use for Bash scripting anymore?

I just finished my second year as a university CS student, so my "real-world" knowledge is lacking. I learned Java my first year, continued with Java and picked up C and simple Bash scripting my second. This summer I'm trying to learn Perl (God help me). I've dabbled with Python a bit in the past. My question is, now that we have ve...

How can I make Perl and Python print each line of the program being executed?

I know that "bash -x script.sh" will execute script printing each line before actual execution. How to make perl and python interpreters do the same? ...

Getting Windows 7 SUA's bash shell working with emacs (EmacsW32)?

Having recently purchased Windows 7 Ultimate in order to gain access to the SUA - http://www.suacommunity.com - subsystem, I have been struggling to get SUA's bash utility (/usr/local/bin/bash) working with EmacsW32. SUA comes with ksh and csh by default, so I installed a community bundle to obtain the bash process. M-x shell normally ...

Correct to check for a command line flag in bash

In the middle of a scrip, I want to check if a given flag was passed on the command line. The following does what I want but seems ugly: if echo $* | grep -e "--flag" -q then echo ">>>> Running with flag" else echo ">>>> Running without flag" fi Is there a better way? Note: I explicitly don't want to list all the flags in a switc...

Bash scripting help

#!/bin/bash usage() { echo "usage: ‘basename $0‘ project_name" } if [ $# -ne 1 ] then usage exit 1 fi mkdir $1 What does this code do? ...

bash grep finding java declarations

i have a huge .java file and i want to find all declared objects given the className. i think the declaration will always have the following signature: className objName; or className objName = or className objName= can someone suggest me a grep pattern which will find these signatures. I have the following (incomplete) : ...

How to use http-delete from the shell

Is it possible to send a HTTP DELETE request from the shell and if so, how? ...

Bash edit file and keep last 500 lines

I am looking to create a cron job that opens a directory loops through all the logs i have created and deletes all lines but keep the last 500 for example. I was thinking of something along the lines of tail -n 500 filename > filename Would this work? I also not sure how to loop through a directory in bash Thanks in advance. ...

Logging into SO with curl

I'm working on a project and I want to log into SO via curl. I use Google as my openID provider which means that I need to log into Google first via its API. Here is the code I have so far #!/usr/bin/env sh . ./params.sh #the script with $username and $password curl --silent https://www.google.com/accounts/ClientLogin \ -d Email=$user...

edit crontab of remote machine server bash remsh rsh

i am trying to edit crontab of remote machine is it possible ? i am running remsh REMOTEHOST -l REMOTEUSER crontab testcronfile getting crontab: can't open your crontab file. error thanks for help HP-UX ...

Change -- to . for all files in a directory

Hello, I need to rename all the files in a directory. Some examples of the source filenames are: alpha--sometext.381928 comp--moretext.7294058 The resultant files would be renamed as: alpha.sometext.381928 comp.moretext.7294058 The number of characters before and after the -- is not consistant. The script needs to work on current...

php script dies when it calls a bash script, maybe a problem of server configuration

Hi!!! I have some problems with a PHP script that calls a Bash script.... in the PHP script is uploaded a XML file, then the PHP script calls a Bash script that cut the file in portions (for example, is uploaded a XML file of 30,000 lines, so the Bash script cut the file in portions of 10,000 lines, so it will be 3 files of 10,000 each ...

Parsing getopts in bash

I've got a bash function that I'm trying to use getopts with and am having some trouble. The function is designed to be called by itself (getch), with an optional -s flag (getch -s), or with an optional string argument afterward (so getch master and getch -s master are both valid). The snippet below is where my problem lies - it is...

Create variables for unknown amount of arguments?

Working on an rsync script and the portion below is in a for loop. What I want to achieve is assign a variable to every arguement after 3. Just confused if I need to create another loop for that or not: #1: name name=$1 #2: ip ip=$2 #3: user user=$3 #4+: folder exlusion #any lines higher than 3 will be created as exl...

How do I capture Chinese input via SCIM with STDIN in Perl?

I use SCIM on Linux for Chinese and Japanese language input. Unfortunately, when I try to capture input using Perl's STDIN, the input is crazy. As roman characters are typed, SCIM tries to guess the correct final characters. ^H (backspace) codes are used to delete previously suggested chars on the command line. (As you type, SCIM tri...

Launch an SWF full screen

I have a swf file (a flash game). I want to run some script to open it in full-screen mode. I'm not attached to any browser, but I do run Linux, so a bash, or generic answer is what I'm looking for. I'm also open to building a lite browser application if need-be. ...