bash

Negate Unsigned Number in Bash

I have a number (hex) and I want the one's complement of it. For example if X = 20 I want bash to perform a negation and return Y = ~X = DF. It doesn't have to be in bash, but it should use a common command line tool that I can wrap into a script. Also note that the numbers should all be unsigned and I'd prefer they don't overflow the...

What is the best practice for dealing with passwords in github?

I've got a little Bash script that I use to access twitter and pop up a Growl notification in certain situations. Whats the best way to handle storing my password with the script? I would like to post this script on GitHub, but I'm wondering what the best way to keep my login/password private while doing this is. Currently the password...

Is it possible for bash commands to continue before the result of the previous command?

When running commands from a bash script, does bash always wait for the previous command to complete, or does it just start the command then go on to the next one? ie: If you run the following two commands from a bash script is it possible for things to fail? cp /tmp/a /tmp/b cp /tmp/b /tmp/c ...

Script executes successfully in commandline but not as a cronjob

I've a bash script that runs a ruby script that fetches my twitter feeds. ## /home/username/twittercron #!/bin/bash cd /home/username/twitter ruby twitter.rb friends It runs successfully in command line. /home/username/twittercron But when I try to run it as a cronjob, it ran but wasn't able to fetch the feeds. ## crontab -e */...

Using a filename with spaces with scp and chmod in bash

Periodically, I like to put files in the /tmp directory of my webserver to share out. What is annoying is that I must set the permissions whenever I scp the files. Following the advice from another question I've written a script which copies the file over, sets the permissions and then prints the URL: #!/bin/bash scp "$1" SERVER:"/var/...

Importing Python module from the Bash

I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that? I have tried an alias like this one: alias program="cd /home/myname/programs/; python; import module; line_of_c...

Bash or PHP script to execute stocked procedure on SQL server

Hi, I am trying to write a bash or PHP script that will execute a procedure on a MS-SQL server, does anybody have pointers on how to do that in the most easiest and convenient way? The script will run on a separate Linux box. Thanks. ...

Calculate difference of numbers in two files

Say I have two files where there is one number per line File 1 file 2 0.12 0.11 0.121 0.454 .... .... I want to create file or output difference between each number on to the screen, so that result looks like 0.0099 -0.333 ...... You can use bash/awk/sed ...

Processing a log to fix a malformed IP address ?.?.?.x

I would like to replace the first character 'x' with the number '7' on every line of a log file using a shell script. Example of the log file: 216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/.... 74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/.... 222.168.17.x [01/Mar/2010:00:27:10 +0100] "GET /etc/.... My humble beginnings.....

How to use a pipe in a foreach statement

I have a for loop I'd like to run in bash like: for i in user_* do; cat $i | ./fetch_contact.php ; done; Always gives an error like -bash: syntax error near unexpected token `done' I assume it has something to do with the pipe, but nothing I try to add in (parenthesis, etc) wrap the pipe sufficiently. How do you use a pipe in a comm...

cd option in bash script

I'm a complete newbie to bash scripting. I remember there was a way to execute the cd command, automatically returning to the current directory (without an explicit cd ..). Any idea? ...

a sufficient way to show logs in a graphical interface using whiptail in bash

hello I'm trying to represent log files via the whiptail's infobox. The only setback is that I don't want to scroll down through hundreds of log lines. Is there a way to make the scroll bar go to the end of the box automatically? Thanks for the help. ...

Bash+cron: Redirecting, and restoring, stdout and stderr produces permission denied

I've got a script that calls out to a bunch of commands, some of which are noisy to stdout, some to stderr, some to both. I intend the script to be run by cron, so I don't want it to be noisy and mail me every day -- only in error conditions. So I do: be_quiet() { # save stderr in FD 3 exec 3>&2 exec &> /dev/null } die() { ...

Bash PS1 settings - how to get the current folder back as the terminal title

Hi all. I recently added these lines to my ~/.bashrc file to show the current branch if i'm in a git working folder, and it works nicely for that. However, what i've lost is that the current folder name used to be shown in the tab for the terminal i have open, and now it isn't: it always just says 'Terminal'. Can i get that back and s...

Help with if statements and else (newbie)

Hi all, I am just new to programming in Unix and have a small issue that I am unsure of how to solve. The objective of this piece of my script is to offer the user various options as to the type of scan they would like to use. This scan detects duplicate files with specified variables depending on the option chosen. I am unable to get i...

bash: redirect (and append) stdout and stderr to file and terminal

To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal I do this: command 2>&1 | tee -a file.txt However, is there another way to do this such that I get an accurate value for the exit status? That is if I test $?, I want to see the exit status of 'command' and not the exit status of tee. I kn...

Escaping 'echo' in batch files

Iditically simple I hope ... I'm trying to create a bash command file on the fly from within an W7 DOS shell: :: inside the .BAT file .. :: check we are in the right directory echo pwd > command.txt :: get the shell to echo its environment variables :: !!!! How do I get around this ... ? echo echo $PWD I thought prefixing the second ...

how do I preserve newlines in a quoted string in bash ?

I'm creating a script to automate the creation of apache virtual hosts. Part of my script goes like this: MYSTRING="<VirtualHost *:80> ServerName $NEWVHOST DocumentRoot /var/www/hosts/$NEWVHOST ... " echo $MYSTRING However, the line breaks in the script are being ignored. If I echo the string, is gets spat out as one line. How can...

Bash shell function error : command not found

Hi all: I am new to bash so please bear with me if this is a dumb question : What I actually want to type in the shell is like this: javac -classpath "emarket.jar" Testclient.java -Xlint:unchecked The fact is, if I manually type the above line into bash, it executes with no error. However, if I craft a customized function in .bashr...

bash: $[<arithmetic-expression>] vs. $((<arithmetic-expression>))

I have just stumbled upon the bash syntax: foo=42 bar=$[foo+1] # evaluates an arithmetic expression When I Googled for this, I found http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html#sect_03_04_05: 3.4.6. Arithmetic expansion Arithmetic expansion allows the evaluation of an arithmetic expression and the substitut...