shell

make my autodownloading shell script better

So I want to download multiple files from rapidshare. This what I currently have. I created a cookie by running- wget \ --save-cookies ~/.cookies/rapidshare \ --post-data "login=USERNAME&password=PASSWORD" \ --no-check-certificate \ -O - \ https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi \ > /dev/null and now...

How do I run a program with a different working directory from current, from Linux shell?

Using a Linux shell, how do I start a program with a different working directory from the current working directory? For example, I have a binary file helloworld that creates the file hello-world.txt in the current directory. This file is inside of directory /a. Currently I am in directory /b. I want to start my program running ../a/hel...

rm fails to delete files by wildcard from a script, but works from a shell prompt

I've run into a really silly problem with a Linux shell script. I want to delete all files with the extension ".bz2" in a directory. In the script I call rm "$archivedir/*.bz2" where $archivedir is a directory path. Should be pretty simple, shouldn't it? Somehow, it manages to fail with this error: rm: cannot remove `/var/archives/mo...

matching text in quotes (newbie)

Hi, I'm getting totally lost in shell programming, mainly because every site I use offers different tool to do pattern matching. So my question is what tool to use to do simple pattern matching in piped stream. context: I have named.conf file, and i need all zones names in a simple file for further processing. So I do ~$ cat named.loca...

How to mkdir only if a dir does not already exist?

I am writing a script to run under the korn shell on AIX. I'd like to use the mkdir command to create a directory. But the directory may already exist, in which case I don't want to do anything. So I want to either test to see that the directory doesn't exist, or suppress the "File exists" error that mkdir throws when it tries to create ...

Variables as commands in bash scripts

Hi all, I am writing a very simple bash script that tars a given directory, encrypts the output of that, and then splits the resultant file into multiple smaller files since the backup media don't support huge files. I don't have a lot of experience with bash scripting; I'm believe having issues with quoting my variables properly to al...

Strengths of Shell Scripting compared to Python

I tried to learn shell(bash) scripting few times but was driven away by the syntax. Then I found Python and was able to do most of the things a shell script can do in Python. I am now not sure whether I should invest my time in learning shell scripting anymore. So I want to ask What are strengths of shell scripting that make it an indis...

How can I add a custom url handler on Windows. Like iTunes itms://

I would like telnet://blah to open putty and not the native windows telnet client. I don't even know what this 'feature' is called under windows so I'm having no luck find any information about it. Thanks in advance, Jan ...

Move top 1000 lines from text file to a new file using Unix shell commands

I wish to copy the top 1000 lines in a text file containing more than 50 million entries, to another new file, and also delete these lines from the original file. Is there some way to do the same with a single shell command in Unix? ...

Cron to Log the ip of a repository with a dynamic ip

Hi, I am using a mac mini with a dynamic ip to store an SVN repository. As an unexpected change of the ip makes it difficult to consistently use the repository, I am interested in creating a cron to log the ip on another server every time it changes. What would be the best way to do this? ...

Why do I get this error using {1..9} in zsh?

I run the following code zgrep -c compinit /usr/share/man/man{1..9}/zsh* I get zsh: no matches found: /usr/share/man/man2/zsh* This is strange, since the following works echo Masi{1..9}/masi This suggests me that the problem may be a bug in Zsh. Is the above a bug in Zsh for {1..9}? ...

How to fix weird issue with iconv on Mac Os x

Hi all, I am on Mac Os X 10.5 (but I reproduced the issue on 10.4) I am trying to use iconv to convert an UTF-8 file to ASCII the utf-8 file contains characters like 'éàç' I want the accented characters to be turned into their closest ascii equivalent so my command is this : iconv -f UTF-8 -t ASCII//TRANSLIT//IGNORE myutf8file.t...

Capture CPU and Memory usage dynamically

I am running a shell script to execute a c++ application, which measures the performance of an api. i can capture the latency (time taken to return a value for a given set of parameters) of the api, but i also wish to capture the cpu and memory usage alongside at intervals of say 5-10 seconds. is there a way to do this without effecting...

How do I test if a variable is a number in bash?

I just can't figure out how do I make sure an argument passed to my script is a number or not. All I want to do is something like this: test *isnumber* $1 && VAR=$1 || echo "need a number" Any help? UPDATE: I managed (whit Charles' help) to do it, but I'm not yet sure it's the best way to do that (even though it worked on my tests)....

Problem with shell script

Hi all, This is a very simple bash script i wrote: #!/bin/bash ITEM_LIST=items.txt LOG_FILE=log.log TOTAL_ITEMS=$(wc -l ${ITEM_LIST} | awk '{ print $1 }') let NOT_FOUND=0 cat ${ITEM_LIST} | while read item; do grep "${item}" ${LOG_FILE} > /dev/null FOUND=${?} if [ ${FOUND} -ne 0 ]; then let NOT_FOUND=NOT_FOUND+1 ...

How to run OS shell commands in IronPython/Mono?

I would like to give IronPython and Mono a try. Specifically doing sysadmin tasks. Which often means running OS commands. In CPython I use the subprocess module for such tasks. But in IronPython (v2.0.1, Mono 2.4, Linux) there is no subprocess module. It seems there is not even an 'os' module. So I can't use os.system(). What would be th...

load the result of an egrep inside a editor (vim/emacs/gedit)

Hey guys, I got some files, after an egrep command, like egrep -l -r '(this|that|those)' * this will list like, 20 files. I don't want to open each one manually, theres any way that I can redirect the result from grep, directly to an editor? So the editor will open those files to me Thanks ...

Embedding a Python shell inside a Python program

I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.) A mockup that illustrates this: How...

Unable to terminate a job without opening it

I run the following code unsuccessfully sudo killall %4 where %4 is my Vim session. How can you terminate a job without foregrounding it? ...

Append git's branch name to command prompt

I wanted to use one of the Git-completion.bash features but I can't customize the look I'd like to have. Here is relevant part of my .bash_profile: source ~/.git-completion.bash function prompt { local WHITE="\[\033[1;37m\]" local GREEN="\[\033[0;32m\]" local CYAN="\[\033[0;36m\]" local GRAY="\[\033[0;37m\]" local BLUE="\[\033[0;34m\]"...