bash

Bash Batch Resize Images File Size Problem

I have a small script that I use to resize all of the images in a directory. I run this script in cygwin and it uses "convert" to do the image resizing. The images change their resolution just fine, but I am having problems with file sizes after the script is run. I typically use this script to resize images dumped out from a Powerpoi...

Linux: How to detect if a computer is being controlled trough serial console

How could I programmatically detect if a Linux machine is being controlled by a user that has logged in using a serial console? I would be doing the checking through BASH. ...

cywin bash script command not found when called from batch

#!/bin/bash echo "Testing" cd "/cygdrive/x/Internal Communications/Riccardo/" filename=htdocs-`date +%A`.tar.gz tar cvzf $filename "/cygdrive/c/Program Files/Zend/Apache2/htdocs" The above script is working when it is called inside cygwin console, but when I try to call it from a bacth file is get command not found for date and tar com...

Simple Bash Script to install MySQL - Need some help

I am writing a simple bash script to install MySQL on Ubuntu. #!/bin/bash apt-get update # Install MySQL5 aptitude -y install mysql-server mysql-client libmysqlclient15-dev However MySQL prompts for a password and confirmation. How do I pass along a root password. Is there an echo I can use? Thank you, Cei ...

Looking to get the env vars of a PID in BASH for a BASH script.

Any way to do this? I have a script that exports a few vars and runs a component. I'm looking to find out the actual values of some of these vars while the process is running. (Which applies here, because I'll be incorporating those values into another script/program) The vars themselves are PID specific (I'm quite new at this, if tha...

Check whether stderr is a pipe in bash

I have a bash script that prompts the user for input with 'read'. If stdout or stderr is piped to something other than a terminal, I would like to suppress this step. Is that possible? ...

Looping over commands to print and execute in BASH

In BASH, I want to do something like this: #!/bin/bash HOST="blah" USER="foo" REMOTE_ROOT="${HOST}:~${USER}/" REP_NAME=`basename $1` TARGET_NAME="${REP_NAME}.git" CMD1="git clone --bare $1 $TARGET_NAME" CMD2="touch ${TARGET_NAME}/git-daemon-export-ok" CMD3="scp -r $...

How do I rename a bash function?

I am developing some convenience wrappers around another software package that defines a bash function. I would like to replace their bash function with an identically-named function of my own, while still being able to run their function from within mine. In other words, I need to either rename their function, or create some kind of per...

Automating svn update

I'm frequently sshing into a server, switching to a specific directory and running svn-update I'm thinking that there's probably a very easy way to automate this, so I can simple specific a subdirectory when I run the script and it'll login via SSH, cd to the right directory and run svn-update. Is this a job for capistrano or could a s...

How do I print the source code of a bash script (on paper)?

I need to print some Bash script on paper. Any recommendations on how to get a nice output with syntax highlighting and all that? I've tried TextMate, but the output had huge fonts (and no syntax highlighting, no colors). ...

Value of global variable doesn't change in BASH.

I am working on a BASH script which has a global variable. The value of the variable changes in a function/subroutine. But the value doesnt change when I try to print that variable outside the function. The Sample code is as follows: #!/bin/bash count= linux_f() { let count=100 } linux_f echo $count The echo statem...

Bash (Mac): edit file and some if commands.

Hello, i want that my bash script does the following: It finds a file, for example: hello.txt It searches for a specific text in the file, for example: hey If it is found, continue to the next thing, if it isn't found, write the text on a new line & continue to the next thing. Can anyone give me the script for this? EDIT: Also i w...

CGI programming with shell scripts

I need to pass the content of the textbox into a variable. i.e. whatever typed in the texbox of the html page needs to be pass to a variable. This is because I am calling HTML (CGI as well) inside linux shell programming. I need to manipulate that variable as I want. Do you have any idea to do it? What I need to do is, I want to get the...

Very strange behaviour when launching Ruby daemons from bash script upon boot

I am using Rightscale to launch an instance on Amazon EC2. All my boot scripts work great and do things like getting the below file names in the folders. The last boot script is the following: #!/bin/bash MAINDIR="/root/username/" ruby ${MAINDIR}insertfd_control.rb stop ruby ${MAINDIR}insertfd_control.rb start ruby ${MAINDIR}inser...

Extract text from hostname

Using OS X, I need a one line bash script to look at a client mac hostname like: 12345-BA-PreSchool-LT.local Where the first 5 digits are an asset serial number, and the hyphens separate a business unit code from a department name followed by something like 'LT' to denote a laptop. I guess I need to echo the hostname and use a combinat...

Bash: Extract parameters before last parameter in "$@"

I'm trying to create a bash script that will extract the last parameter given from the command line into a variable to be used elsewhere. Here's the script I'm working on: #!/bin/bash # compact - archive and compact file/folder(s) eval LAST=\$$# FILES="$@" NAME=$LAST # Usage - display usage if no parameters are given if [[ -z $NAME ...

sh command: exec 2>&1

What will this command do? exec 2>&1 ...

bash script 'here strings'

I am going to be running a C program from inside a bash script. The c program expects inputs from the user. total number of inputs are 7. which are on 7 different lines. for example Please enter input1: 1 Please enter input2: 2 Please enter input3: 3 so on.. I did some reading up and found out that bash here strings are used for ...

Use of \c in shell scripting

I am editing someone else scripts and I see s/he has used this \c very often like echo "bla bla \c" which when used simply prints bla bla \c in screen. So, I was wondering why use it or may be I am missing something, because it is doing nothing at all ? I checked escape characters and I didn't find any such thing as well. Is there...

Shell: SVN status pipe to php to check syntax

I know this is simple but I just cant figure it out. I have a bunch of files output by "svn st" that I want php to do a syntax check on the command line. This outputs the list of files: svn st | awk '{print $2}' And this checks a php script: php -l somefile.php But this, or variants of, doesn't work: svn st | php -l '{print $2}' Any...