shell-scripting

Can you grep a file using a regular expression and only output the matching part of a line?

I have a log file which contains a number of error lines, such as: Failed to add [email protected] to database I can filter these lines with a single grep call: grep -E 'Failed to add (.*) to database' This works fine, but what I'd really like to do is have grep (or another Unix command I pass the output into) only output the email ad...

modifying font size using shell script

Is there any way to change the font size of terminal window(GNOME or KDE) from inside a shell script Actually I want to display a file in a particular format on screens of all sizes. Can i do it using scripts?? ...

Add (collect) exit codes in bash

I need to depend on few separate executions in a script and don't want to bundle them all in an ugly 'if' statement. I would like to take the exit code '$?' of each execution and add it; at the end, if this value is over a threshold - I would like to execute a command. Pseudo code: ALLOWEDERROR=5 run_something RESULT=$? ..other things...

UNIX ssh script, running commands on remote server

I would like to create a script that automatically logs into a remote server and grabs a file on the server. The script already logs into the server however the commands are not run on that machine. Once I disconnect from the remote server, the commands are run on the client machine. !/bin/sh ssh -o PreferredAuthentications=publickey b...

How can I copy all my disorganized files into a single directory? (on linux)

I have thousands of mp3s inside a complex folder structure which resides within a single folder. I would like to move all the mp3s into a single directory with no subfolders. I can think of a variety of ways of doing this using the find command but one problem will be duplicate file names. I don't want to replace files since I often hav...

How do I make the dock icon stop bouncing after my app wrapper script starts?

So I recently made an .app wrapper for a zsh script, but when I run it, the icon for the app keeps hopping in the Dock. The app is basically: % find Example.app -type f Example.app/Contents/Info.plist Example.app/Contents/MacOS/wrapper.sh % cat Example.app/Contents/Info.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLI...

Check if a function exists from a bash script.

How can I determine if a function is already defined in a bash script? I am trying to make my .bash_login script portable between systems, so I want to add logic to only call a function if it exists. I want to add __git_ps1() to PS1 only if that function exists on that system. This funciton normally defined in git-completion.bash whic...

ASH variable indirect reference

I'm trying to port a script from BASH to ASH (Almquist SHell) and am running into a problem with indirect references. The following function cmd() { # first argument is the index to print (ie label) arg=$1 # ditch the first argument shift # print the label (via indirect reference) echo "${!arg}" } should produc...

PHP shell execute - Without waiting for a return

Hi, I have this process intensive task that i would like to run in the background. The user clicks on a page the PHP script runs and finally based on some conditions if required then it has to run a shell script EG: shell_exec('php measurePerformance.php 47 844 [email protected]'); Currently I use shell_exec BUT this requires the scrip...

Is there any difference between using typeset in ksh to simply setting a variable?

Are the following 2 lines completely equivalent? If not what's the difference? I've seen plently of shellscripts utilize number 1 and was just wondering what it gives you compared with number 2. typeset TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties" TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.proper...

How To Find Checked Out Files

Hi all, I'm using Visual Source Safe 6.0d (work requirement) and I've been trying to hack together a little shell script to allow me to easily remove a source tree or warn me if I've got files checked out so I can make sure I don't accidentally delete work. Is there any way to tell if files are checked out other than checking the read-...

sed whole word search and replace

Hi, How do I search and replace whole words using sed? Doing sed -i 's/[oldtext]/[newtext]/g' will also replace partial matches of [oldtext] which I don't want it to do. Thanks, Kenneth ...

Forcing the order of output fields from cut command

I want to do something like this: cat abcd.txt | cut -f 2,1 and I want the order to be 2 and then 1 in the output. On the machine I am testing (FreeBSD 6), this is not happening (its printing in 1,2 order). Can you tell me how to do this? I know I can always write a shell script to do this reversing, but I am looking for something us...

Problems when trying to exectue exec("unix2dos xxx") in PHP/Apache

In a previous post, I was trying to update the encoding for a download file from php. One of the suggestions was to run the unix2dos command before sending the file to the user. This works great when I run the command on the linux box, but when I try and run the command from php I get nothing. Here is what I tried: $cmd = "unix2dos -...

Using 'expect' to automatically send in password

I am trying to copy a file from my remote server to my local. Here's my script to run it, by using 'expect' to automaticlally send in password scp user@host:/folder/myFile ./ expect "Password: " send "myPassword" When I run this, it still prompts for "Password", what is wrong? ...

Enable/Disable a mounted drive using a powershell script

I have a disk drive that is mounted by an API. The drive is mounted but defaults to disabled. Does anyone know how to use powershell script to enable the drive? (Windows Server 2008, Powershell 1.0) ...

Looking for way to automate testing kshell app

I inherited a shell-script application that is a combination of kshell scripts, awk, and java programs. I have written JUnit tests for the java pieces. Is there a good way to do something similar for the kshell scripts and awk programs? I have considered using JUnit and System.exec() to call the scripts, but it seems like there shou...

Does renice on a parent renice the child?

I know if I nice a shell script (ie: before it runs) all processes that start from the shell script will also be niced. What if I start a shell script and the renice it, do all the child processes become reniced as well? Looked in the renice man pages and there are no mention of child processes. ...

How can I use shell scripting to send an email when Handbrake gets done?

I am currently encoding a lot of home videos converted from VHS tapes using Handbrake. I am using Ubuntu 64bit dual core machine and usually queue a lot of these videos. My question is how can I use shell scripting to keep checking on the handbrake process and send me an email when Handbrake finishes encoding a video file. One idea was ...

How to zip only new files from running a report in a Bash script?

I am writing a script that will look in a custom reports directory, copy it to a working folder, along with the data files that it will look at, runs the report, zips the newly created files, and uploads them to another server. The problem that I'm running into is that I don't know what the newly created files will be called at all (n...