bash

Bash script, need help with homework assignment

Bash script, need help with ...

Tutorial/Guide to create a classic, small Linux application in a package (Debian)

I've made a small script in my machine, and an alias in .bashrc that calls it. It's a bash script with 3 lines, but it can grow. Now, some people in my team found it useful, and want to use it. Instead of saying "copy this alias, do this, do that, install that lib" I was thinking about creating a simple package to be a little more prof...

Bash script not exiting immediately when `exit` is called

I have the following bash script: tail -F -n0 /private/var/log/system.log | while read line do if [ ! `echo $line | grep -c 'launchd'` -eq 0 ]; then echo 'launchd message' exit 0 fi done For some reason, it is echoing launchd message, waiting for a full 5 seconds, and then exiting. Why is this happening and h...

OS X + Crontab: How do you run SCP via cron?

This works fine when I run it by hand: #!/bin/bash eval `ssh-agent` ssh-add /usr/bin/scp me@server:~/file ./ exit 0 However, when the cron runs the file is never touched. I know the ssh keys are right - replace that scp with an ssh and it runs fine. ...

About stdout/stderr redirections...

I wrote a code to get a runtime error intentionally: int main() { int a=5; printf("Hello World\n"); printf("a=%s\n", a); } It gives: $ ./error.o Hello World Segmentation Fault $ Now, to record the runtime errors, I do: $ ./error.o > so.txt $ ./error.o &> soe.txt But both the files are empty. Why? EDIT: I'm actually writing ...

How to handle filenames with dollar character ($) in bash ?

Hi, I have managed to cobble together the following script that moves files from one Samba share to another. It seems to work for all legal windows filenames except when there is a dollar character ($) in the filename. Typical filename it fails on is: ~$file.doc Any help would be appreciated. #!/bin/bash # Script to move old files fro...

Extracting words in quotes in shell script

Hi! I am making a shell script that will automate the install process of Arch Linux AUR packages. I need to list all dependencies of the package (to check if they are installed), they appear like this in install script: depends=('sdl' 'libvorbis' 'openal') The easiest way (or the only idea) that I could come up with is something like...

Mac OS X - bash default pathname expansion or bug

I'm trying to run the following line of script in bash on Mac OS X 10.6.4 (from this question): $ export EDITOR='mvim -f -c "au VimLeave * !open -a Terminal"' Alas, what I get is something unexpected: $ echo $EDITOR mvim -f -c "au VimLeave Desktop Documents Downloads Library Movies Music Pictures Public Sites bin !open -a Terminal" ...

Find cron jobs that run between given times

Is it possible to find all entries in a crontab that run between time X and time Y without having to parse the cron time entries myself? I'm mainly concerned with time hour and minute, not so much the other 3 time fields. ...

regex for finding date dir

i am looking to search for in dir ... a2010-02-10 how to search the ls all dir in with date format ls -d *(\d+)-(\d+)-(\d+) its not working like perl what is the right format ...

Using netcat (nc) as an HTTP proxy server and monitor

Is it possible to use the Unix netcat (nc) program to create a TCP proxy server and monitor? I would like all TCP traffic to be passed across the pipe, as well as sent to stdout for monitoring. Note this will be used for monitoring HTTP traffic between a hardware device and an HTTP server. ...

OS X Bash Auto-Completion question (spaces in directory names)

Hi all. I'm pretty new to this whole Terminal business and had things working nicely on my old laptop with Snow Leopard installed. New laptop with Snow Leopard works differently, however. When using the terminal, when trying to get auto-completion to work, it won't autocomplete for directory names with spaces in them. I know I can type...

How to redirect a program that writes to tty?

This is the un-redirected output (if you don't know what module is, it doesn't matter much): $ module help null ----------- Module Specific Help for 'null' ----------------------- This module does absolutely nothing. It's meant simply as a place holder in your dot file initialization. Version 3.2.6 S...

AWK output to bash Array

Hi all, Im trying to put the contents of a simple command in to a bash array however im having a bit of trouble. df -h | awk '{ print $5" "$6 }' gives percentage used in the file systems on my system output looks like this: 1% /dev 1% /dev/shm 1% /var/run 0% /var/lock 22% /boot 22% /home 22% /home/steve I would then like to put ea...

How to handle rsync in bash script to perform data sync backward from the secondary server to the primary server ?

I have two separate physical servers PRIMARY and SECONDARY connected with a ethernet switch of 100 mbps and i want to rsync files from my PRIMARY /home to SECONDARY /home and now after working for two hours in my SECONDARY server i have created some data in /home and so i want again the rsync to transfer the new data back to PRIMARY serv...

Generate all possible strings from a list of token

Hi I have a list of tokens, like: hel lo bye and i want to generate all the possible combinations of such strings, like: hello lohel helbye byehel lobye byelo Language is not important, any advice? I found http://stackoverflow.com/questions/3846123/generating-permutations-using-bash, but this makes permutation on a single line...

Shell Bash: Passing argument to alias

Hello, Is it possible to do the following: I want to run the following: mongodb bin/mongod in my bash_profile I have alias = "./path/to/mongodb/$1" Thanks everyone! ...

How can I know if a character shows on the shell?

I am writing a program with special characters in it. Characters like װאבדג (hebrew). Using some Ubuntu I had handy here I could get them to work inside the X environment (inside gnome-terminal). In rxvt, I get strange characters instead of what I have in the file; and in bare xterm I get some of them. The file itself may be just as si...

git stderr output can't pipe

I'm writing a graphical URI handler for git:// links with bash and zenity, and I'm using a zenity 'text-info' dialog to show git's clone output while it's running, using FIFO piping. The script is about 90 lines long, so I won't bother posting it here, but here's the most important lines: git clone "$1" "$target" 2>&1 | cat >> /tmp/gith...

Bash cgi output xmlrpc

Hi, I have this Bash Script: #! /usr/local/bin/bash SCGI_SOCKET=unix:///tmp/rpc.socket echo -n rT $(rtxmlrpc system.client_version)/$(rtxmlrpc system.library_version) echo -n \ [$(rtcontrol -qosize \* | awk '{ SUM += $1} END { print SUM/1024/1024/1024 }') GiB loaded] echo -n , D:$(rtxmlrpc to_mb $(rtxmlrpc get_down_total)) MiB echo -n ...