bash

Send a command to a process

Using bash, is it possibile to send the equivalent of a space bar stroke to a process? If so, how can that be done? Edit to clarify a bit what I want to achieve: let's say I've got an mplayer process running and I want to pause the execution of the current song, how would I achieve this? ...

Better way to make a bash script self-tracing?

I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I am currently doing: #!/bin/bash # if last arg is not '_worker_', relaunch with...

Printing Stdout In Command Line App Without Overwriting Pending User Input

In a basic Unix-shell app, how would you print to stdout without disturbing any pending user input. e.g. Below is a simple Python app that echos user input. A thread running in the background prints a counter every 1 second. import threading, time class MyThread( threading.Thread ): running = False def run(self): self....

How to retrieve the first word of the output of a command in bash?

I have a command, for example: echo "word1 word2". I want to put a pipe (|) and get word1 from the command. echo "word1 word2" | .... I don't know what to put after the pipe... Thanks in advance ...

How to enable tab completion from the terminal specific to the executable

In bash, I believe it is possible to enable tab completion on the terminal for terms that are specific to the executable being invoked. For example, given an executable "eat" with valid arguments {cake, carrot, banana}, typing 'eat car' should complete to 'eat carrot'. I believe this is possible because I have seen it with 'ant' tab-c...

How to build a conditional assignment in bash?

I'm looking a way to build conditional assignments in bash: In Java it looks like this: int variable= (condition) ? 1 : 0; Thanks in advance ...

How to replace a line in bash

How can I replace a line that starts with "string1" with "string2 lala" using Bash script? Thanks in advance ...

How to get physical memory in bash

How can I get the total physical memory in bytes of my Linux PC? I need to assign it to a bash script variable Thanks in advance ...

Bash init.d script detect that mysqld has started and is running

I'm working on my dedicated server running CentOS. I found out that one of my applications which starts up via a script in /etc/init.d/ requires MySQL to be running, or else it throws an error, so essentially I currently have to start it by hand. How can I detect, in a bash script (#!/bin/sh), whether the MySQL service has started yet? ...

How to get line count from variable (from MYSQL query)?

My problematic code: testMYSQL=`mysql -u $mysqlUser -p$mysqlPass -h $mysqlHost --skip-column-names --batch -D $mysqlDB -e "SELECT $select FROM $mysqlTable WHERE nameTXT='test';"` $testMYSQL now contains: test test test Then I do: TEST=$(echo $testMYSQL | wc -l) echo "$TEST" I would of thought that would work, but it doesn...

How to find out the exact RSS XML path of a website?

How do I get the exact feed.xml/rss.xml/atom.xml path of a website? For example, I supplied "http://www.example.com/news/today/this_is_a_news", but the rss is pointing to "http://www.example.com/rss/feed.xml", most modern browsers have this features already and I'm curious how did they get them. Can you cite an example code in ruby, py...

Filtering Filenames with bash

I have a directory full of log files in the form ${name}.log.${year}{month}${day} such that they look like this: logs/ production.log.20100314 production.log.20100321 production.log.20100328 production.log.20100403 production.log.20100410 ... production.log.20100314 production.log.old I'd like to use a bash script ...

What does "< <(cmd args)" mean in the shell?

When looping recursively through folders with files containing spaces the shell script I use is of this form, copied from the internet: while IFS= read -r -d $'\0' file; do dosomethingwith "$file" # do something with each file done < <(find /bar -name *foo* -print0) I think I understand the IFS bit, but I don't un...

Bash: easy way to put a configurable load on a system?

In order to test how a program reacts when system resources become scarce (mainly the CPU but I'm interested in disk I/O too), I'd like to put an arbitrary load on the system. Currently I'm doing something like this: #!/bin/bash while true do echo "a" >> a.txt md5 a.txt done I could also start mp3-encoding audio files, or wh...

Remove line from a file using a variable line number

Hi Guys, This is probably a simple one to answer, but I'm stuck, so here goes. sed '3d' filename # (or something like that) I'm having trouble trying to use a $VARIABLE instead of the number. Anyone know how to get this to work, or any alternative options? Regards Paul ...

How do I display a tree of things in Bash?

How do I make a tree of all things with bash? What is the command? ...

Bash: using commands as parameters (specifically cd, dirname and find)

This command and output: % find . -name file.xml 2> /dev/null ./a/d/file.xml % So this command and output: % dirname `find . -name file.xml 2> /dev/null` ./a/d % So you would expect that this command: % cd `dirname `find . -name file.xml 2> /dev/null`` Would change the current directory to ./a/d. Strangely this does not work. ...

Howto Pass A String as Parameter in AWK within Bash Script

I have a text file which I want to filter using awk. The text file looks like this: foo 1 bar 2 bar 0.3 bar 100 qux 1033 I want to filter those files with awk inside a bash script. #!/bin/bash #input file input=myfile.txt # I need to pass this as parameter # cos later I want to make it more general like # coltype=$1 col1type="foo" ...

Use a grepped file as an included source in bash

I'm on a shared webhost where I don't have permission to edit the global bash configuration file at /ect/bashrc. Unfortunately there is one line in the global file, mesg y, which puts the terminal in tty mode and makes scp and similar commands unavailable. My local ~./bashrc includes the global file as a source, like so: # Source globa...

Aquireing the entire string sent to the shell for execution

I have a bash script that looks like this (called job_result.sh): #!/bin/bash $* && zenity --title "Job result" --info --text "SUCSESS: Job '$*'completed" && while pidof zenity > /dev/null; do /usr/bin/wmctrl -a "Job Result" && sleep 2; done When i execute it with: $ ./job_result.sh echo "arf" && sleep 10 I want the following to ha...