bash

Trick an application into thinking its stdin is interactive, not a pipe

I'm trying to do the opposite of http://stackoverflow.com/questions/1312922/detect-if-stdin-is-a-terminal-or-pipe-in-c-c-qt I'm running an application that's changing its output format because it detects a pipe on stdout, and I want it to think that it's an interactive terminal so that I get the same output when redirecting. I was thi...

YYYY-MM-DD format date in shell script

I tried using $(date) in my bash shell script, however I want the date in YYYY-MM-DD format. How do I get this? ...

In bash, what is the simplest way to configure lighttpd to call a local python script based on a particular URL?

In bash, what is the simplest way to configure lighttpd to call a local python script while passing any query string or name-value pairs included with the URL as a command line option for the local python app to parse? Example: www.myapp.com/sendtopython/app1.py?Foo=Bar results in the following occurring on the system. >python app1.py...

BASH : List files by last edited date?

Let's say I have a directory like- /home/user/ and I want to list EVERY file (even in sub directories) under that folder and order them by the date they were last edited. Can I and if so, how? Thanks! ...

How to create a bash script to check the SSH connection?

I am in the process of creating a bash script that would log into the remote machines and create private and public keys. My problem is that the remote machines are not very reliable, and they are not always up. I need a bash script that would check if the SSH connection is up. Before actually creating the keys for future use. ...

linux shell script: split string, put them in an array then loop through them

In a bash script how do I split string with a separator like ; and loop through the resulting array? ...

Getting another program's output as input on the fly

I've two programs I'm using in this way: $ c_program | python_program.py c_program prints something using printf() and python_program.py reads using sys.stdin.readline() I'd like to make the python_program.py process c_program's output as it prints, immediately, so that it can print its own current output. Unfortunately python_prog...

BASH - Single quote inside double quote for SQL Where clause

I need to send a properly formatted date comparison WHERE clause to a program on the command line in bash. Once it gets inside the called program, the WHERE clause should be valid for Oracle, and should look exactly like this: highwater>TO_DATE('11-Sep-2009', 'DD-MON-YYYY') The date value is in a variable. I've tried a variety o...

How to split a file and keep the first line in each of the pieces?

Given: One big text-data file (e.g. CSV format) with a 'special' first line (e.g., field names). Wanted: An equivalent of the coreutils split -l command, but with the additional requirement that the header line from the original file appear at the beginning of each of the resulting pieces. I am guessing some concoction of split and hea...

Use find, wc, and sed to count lines

I was trying to use sed to count all the lines based on a particular extension. find -name '*.m' -exec wc -l {} \; | sed ... I was trying to do the following, how would I include sed in this particular line to get the totals. ...

Bash Script to remove iframe virus

I want a bash script to read all files recursively in a directory and remove some code (i.e a iframe virus) from it and save back the orignal file. ...

Bash - $PATH and ${PATH}

What is the difference between using an environment variable, like PATH, as $PATH or ${PATH}? ...

What's wrong with my bash array?

Can anyone tell me why this bash script works if I cut and paste it to the terminal but throws "server_prep.sh: 7: Syntax error: "(" unexpected" when launched using $ sudo sh server_prep.sh ? #!/bin/sh #Packages apt-get -y install ssh libsqlite3-dev ruby-full mercurial #Gems required_gems = ( rake rails sqlite3-ruby ) #Set up directo...

using gawk in a shell script

I want to do something of the sort: for i in 1 2 3 do gawk '{if ($i==$2) {print $0;}}' filename done is this possible? thanks ...

Compress a Mysqldump that is SSH'd to another machine

I have the following: mysqldump -u xxxx -h localhost --password=xxxxx databasename | ssh [email protected] "dd of=httpdocs/backup`date +'%Y-%m-%d-%H-%M-%S'`.sql" ...which SSH's a mysqldump to a remote machine. I need to compress the mysqldump before it is SSH'd as the dump is 500mb and its e...

source all files in a directory from .bash_profile

I need to allow several applications to append to a system variable ($PYTHONPATH in this case). I'm thinking of designating a directory where each app can add a module (e.g. .bash_profile_modulename). Tried something like this in ~/.bash_profile: find /home/mike/ -name ".bash_profile_*" | while read FILE; do source "$FILE" done; but i...

Using bash(cygwin) inside C# program

Hi, i need to use bash shell "inside" C# program. I want to mimic user typing in interactive mode and running cygwin commands. i created a process that runs bash and redirect stdin,stout and std error but i can;t get tty to work attached is a sample code that starts bash process and redirect the input/output. the problem is that i don...

Bash Script - Running current or new instance of an application

I added a shortcut to an application in ubuntu. Each time i press shortcut keys, a new instance of application is created. I need only one instance, what script i can use to open the existing instance of application or creates a new one if the application is not running? ...

Testing for GUI in .bashrc

Is there a good way to test whether I am logging into a text shell or starting a GUI session in my .bashrc? For example, to set my editor to gedit if in gnome and emacs if using a command line. ...

Starting a screen session on startup with ubuntu

I'm using amazon EC2 for a service that I'm starting, however when I try and start a screen session during the startup script (which is ran during the bootup process) the screen never gets started. I've made sure to run apt-get install screen -y, however I'm not sure how to make the screen start correctly. Any help? -UPDATE- here's th...