bash

Bind9 DNS Zone Transfer Script - Bash script to avoid duplicates

I created a bash script to transfer my zones between my primary and secondary DNS server. It downloads my zone list from the primary and checks for any new zones and then downloads and inserts those zone files into the zone directory and into the .local file for bind. The problem I have is that if the zone file does not exist, the scrip...

Can Python be made to generate tracing similar to bash's set -x?

Is there a similar mechanism in Python, to the effect set -x has on bash? Here's some example output from bash in this mode: + for src in cpfs.c log.c popcnt.c ssse3_popcount.c blkcache.c context.c types.c device.c ++ my_mktemp blkcache.c.o +++ mktemp -t blkcache.c.o.2160.XXX ++ p=/tmp/blkcache.c.o.2160.IKA ++ test 0 -eq 0 ++ echo /tm...

How do I determine if a gif is animated?

I have large number of files with .gif extension. I would like to move all animated gifs to another directory. How can I do this using linux shell? ...

Hiding xfce4-panel from command line

Hello, Is there a way to hide xfce4-panel from command line. If no any other solutions how to hide it from terminal ? Regards, Levon ...

Why can't I call `history` from within Ruby?

I can run Bash shell commands from with a Ruby program or irb using backticks (and %x(), system, etc). But that does not work with history for some reason. For example: jones$ irb --simple-prompt >> `whoami` => "jones\n" >> `history` (irb):2: command not found: history => "" From within a Ruby program it produces this error: /usr/lo...

bash: complex test in find command

I would like to do something like: find . -type f -exec test $(file --brief --mime-type '{}' ) == 'text/html' \; -print but I can't figure out the correct way to quote or escape the args to test, especially the '$(' ... ')' . ...

String comparison precedence in Bash

The following example will compare all files in a directory to input string ($string) and return matching filename. It is not very elegant and efficient way of accomplishing that. For speed purposes I modified for condition to only compare to files that start start with first word of $string. Problem with this script is following - I h...

Getting user to authenticate the password

I'm trying to write a sh coding to get the user to authenticate the password by comparing the user input to the first 32 characters of a file. So basically if the password is correct it would run TaskMenu.csh if its wrong the program would exit. #!/bin/sh clear echo -e " Please Enter the Password to access the TaskMenu:" read PW if (! -...

Locate files which ONLY contain printable characters in bash script

Hi there, I'm trying to write a bash script that looks at a directory full of files and categorises them as either plaintext or binary. A file is plaintext if it ONLY contains plaintext characters, otherwise it is binary. So far I have tried the following permutations of grep: #!/bin/bash FILES=`ls` for i in $FILES do ########GREP...

git: hash autocomplete

Is there any chance to configure git to autocomplete the hashes when pressing TAB? Edit: Please note that this question is not about autocomplete, but about hash autocomplete. See my comment to VonC's answer. ...

git: Automatic tagging of releases

How do you tag your release versions in git? Now I have each release identified by build number, but they increment even if there are no changes in the repo. My idea is to have it generated automatically on successful deployment on staging server. E.g. run Hudson build when successful, add new tag, i.e. 1.0-1 on next successful build ...

Is there a way to run a python script that is inside a zip file from bash?

I know there is a way to import modules which are in a zip file with python. I created kind of custom python package library in a zip file. I would like to put as well my "task" script in this package, those are using the library. Then, with bash, I would like to call the desired script in the zip file without extracting the zip. The ...

git: empty arguments in post-receive hook

I'm writing post-receive hook basing on the post-receive-email script from the contrib dir, but it seems that the oldrev and newrev arguments are empty. The script looks like this: #!/bin/bash oldrev=$(git rev-parse $1) newrev=$(git rev-parse $2) The script runs on push, but all $1, $2, $oldrev and $newrev are empty. Should I config...

What am I doing wrong in this bash function?

I'm trying to create a function that goes to a specific directory, and if a single argument is specified add that to the directory string. But no matter what I try I can't get it to work and bash always reports that X is not a directory even though if I copy/paste it to a new command line it works from there. function projects () { DI...

Continually running PHP script using Bash

I have a long running PHP script that has a memory leak which causes it to fail part way through. The script uses a 3rd party library and I haven't been able to find the source of the leak. What I would like to do is create a bash script that continually runs the PHP script, processing 1000 records at a time, until the script returns a...

Do I use $? correctly ?

I want to verify if I can connect to a database (PostgresSQL) into a bash script I execute the following command (PGUSER, PGDATABASE... are set) psql -f sql/test_connection.sql > /dev/null 2>&1 When I echo $? it shows 0 if success, 2 if not. It works fine in a terminal. When I put it into a bash script the result is always 0 even...

bash: passing params from $3 onwards to another program (say tar)

let's say my script takes filenames starting from $3 e.g. archive u 2342 a.txt b.png c.html d.js archive u 2222 a.txt b.png I want to zip all the files listed starting from $3 How can I do that? thanks ...

Average execution time

Hi, is there any nice GNU way how to measure average (worst case, best case) execution time of some command line program? I have image filter, unspecified amount of pictures, filtering them using for-loop in bash. So far I am using time, but I can't find a way how to get some statistics. ...

How to save "history" automatically depending on the directory

Hi, I work extensively using the shell. When I continue working on some project one week later, I go to some "folder" and realize that I do not remember what I was doing. Sometimes and before stopping work what I do is: history > DIRX_HISTORY_20100922 so later I have a look at the commands I used, I can remember much better what I w...

Writing output from a socket

I have 2 machines A and B. In machine A, I do echo "Hello World" > /dev/tcp/{Bs_ip}/12345 In machine B, how do I write a script that runs in the background, listens on port 12345, and prints whatever it receives from port 12345 to stdout? BTW both machines are running Red Hat Enterprise Linux AS 4. Thanks ...