Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

1
vote
1answer
825 views

Bash Script: Redirecting to file gives “Illegal Instruction”

I'm trying to use a bash script for a study assignment. As a bash noob, I tried to adapt an existing one to suit my purpose: Compile/Make a C-program with different compile arguments, execute it and ...
1
vote
2answers
215 views

append text to file including multiple quotes

I want to do this: echo alias get_python_lib='python -c "from distutils.sysconfig import get_python_lib; print get_python_lib();"' >> ~/.bash_aliases The result in my ~/.bash_aliases file is: ...
1
vote
1answer
214 views

regex to put an actual newline at every \n

I'm writing a bash script that will deal with blob data that needs to be written to a file. The data inserted into the blob is separated by newlines. The command line mysql -e select blobfield from ...
0
votes
1answer
580 views

Bash Script to Run a Command in Screen

I need to create a bash script that would open a new screen session, then run a program in tha session. Is it possible to do that? Any help appreciated.
0
votes
1answer
755 views

How to write an efficient bash script to find and sort files and directories, extracting dates?

Background: It is a temporary measure to load some test data into a test environment (a Sybase database). I have a bunch of files I have to import into database daily. These files are organized as ...
2
votes
2answers
3k views

How get full path to target of link

If I have a symbolic link /var/opt/foo created with ln -fs /path/to/target/dir foo. How can I in a script that sees only the link get /path/to/target/dir? What I want to achieve in the script is rm ...
6
votes
5answers
3k views

Delete all files (except the four newest) throughout directories using a Bash script

I'm looking for a Bash script that will go into a list of directories and delete all but the four most recently created files. How can I do this?
2
votes
2answers
519 views

Putting the cursor back at the bash prompt after a script returns delayed output

Just a minor issue. I'm writing a simple bash script that starts and stops Jetty. When I execute it, the script immediately puts my cursor back on the bash prompt. However, as Jetty starts up and ...
9
votes
3answers
9k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
3
votes
5answers
735 views

What is the simplest way to remove lines from one file matched with lines from another file?

What's the simplest way to remove lines from one file matched with lines from another file? For example, if I have the following files: file1.csv: u2@domain.com file2.csv: ...
6
votes
1answer
3k views

Automated Interaction with Google Chrome

All right SU, I have a fun nut to crack. I have 8 screens set up in a line, all hooked into one beefy G5 running Snow Leopard (yes, 4 graphics cards; about 15,000 pixels wide!). I am setting up a ...
0
votes
1answer
245 views

Errors from a bash script run from cron

My rsync cron job does not run at the expected time and below are my scripts. It gives me the error: crond[9231]: unable to create mail file /var/spool/cron/cron.YSwg8Z/cron.root.9290: cron output ...
1
vote
1answer
367 views

How to stop printf from printing escape codes in shell script?

When I run a simple shell script with the following code: #!/bin/sh printf "\e[32m Hello World\n" I get \e[32m Hello World as output as opposed to a green Hello World output.
2
votes
2answers
2k views

How do I use the -ne flag for echo in a shell script?

I'm trying to create a shell script to take an argument and use it to name a terminal tab. So if the script's name is tabnm, tabnm "test" should rename the current tab "test" This is my code: ...
1
vote
2answers
289 views

Bash shell string concatenation

I'm trying to create a string and pass it to rm, but I'm having some difficulty making it work. I would like to remove everything in MY_PATH. Below is what I've attempted. MY_PATH=/my/directory/ ...
0
votes
1answer
30 views

Piping results back into the program that generates them

I've got a program that can take input from stdin and produces output in the stdout like this: cat initial_input.txt | myprogram myindex myoptions - | filter_output > outfile.txt The program ...
2
votes
2answers
547 views

appending timestamp to tail -f results

I would like to have a timestamp printed in front of every line that comes out of a "tail -f outputfile", so that I know when is each line printed in. Something like: [...] 20110617_070222:results ...
8
votes
4answers
6k views

how to grep and print the next N lines after the hit?

I would like to grep for an occurrence in a text file, then print the following N lines after each occurrence found. Any ideas?
0
votes
2answers
2k views

FTP from bash script running from cron not working

I have a script that is run by cron to create backup of a MySQL database and some files. After creating a tar ball and encrypting it with openSSH I have to put it on a remote ftp server. Following is ...
2
votes
2answers
1k views

how to properly use $1 in an alias with two arguments

i have to compare a number of files and I don't want to change the command in two places all the time. so i want to create an alias in bash. alias gd='gvimdiff $1 dir/$1' so that i can get ...
1
vote
1answer
646 views

BASH: How to best filter directories of files for a certain date range in the filename?

Here's the picture... Date format: Y%m%d%H%M%S% This is my filename format: file_sub1_20110501000000.txt Directory structure: dir/ sub1/ file_sub1_20110501003000.txt ...
2
votes
4answers
2k views

BASH - grep - works on command line, but not script

I am trying to get the number of occurrences in a script and when running the command on the command line, it works fine, but not in a script. Both variables are initialized. FILE_PATH is the ...
1
vote
1answer
265 views

How to script for a graceful program 'quit' as 'kill' leaves a mess behind

On PClinuxOS 2010 I use SMB4K to manage LAN shares. It works perfectly, unless I forget to quit SMB4K before shutting down the computer. If I forget, AND a mounted network share has gone offline, the ...
0
votes
1answer
3k views

start-stop-daemon works at command line but doesn't work in /etc/init.d script

I'm trying to get a starter script (for a ruby gem called ar_sendmail) working in /etc/init.d/ar_sendmail: #! /bin/sh echo "in /etc/init.d/ar_sendmail" DIR=/home/max/work/e_learning_resource/trunk ...
0
votes
2answers
199 views

Awk script usage

where should the awk program command file be placed when I am trying to run the awk command inside a shell script? I guess it should be in the same directory, but not sure. Please help.
0
votes
1answer
5k views

Why can't I delete a file with a bash script

This may be a silly question, but I can't seem to run rm from a bash script and remove a file. #!/bin/bash rm -rf myjunk.out exit 0; doesn't remove myjunk.out
0
votes
1answer
391 views

Execute a command and put the results into a variable… all in a bash script

I'm working on a bash script that backs up a configuration file before copying over a new file. Here's what my snippet looks like: mv ~/myStuff.conf ~/myStuff.conf.bak cp ~/new/myStuff.conf ...
1
vote
1answer
1k views

Shell script to rename multiple files from their parent folders name

I have a file structure like this: 00000010 000000001.file1 000000001.file2 00000020 00000003.file1 00000003.file2 00000003.file3 ... So there are folders with 8-digit names containing one ...
3
votes
3answers
5k views

Process each line of a file in bash

When I want to do something with each line in a file I usually write cat my_file | while read a do gzip "$a" done The gzip is just an example it can be anything. What I'm wondering is if there is ...
2
votes
1answer
4k views

Handle filename with spaces inside Bash-script

In my Bash-script i have to handle filenames with spaces. These are the important lines inside my script: mp3file="/media/d/Music/zz_Hardcore/Sampler/Punk-O-Rama\ Vol.5\ \[MP3PRO\]/01\ -\ Nofx\ -\ ...
0
votes
1answer
2k views

Unable to specify parameters to cvlc in a script

I'm creating a script that issues a few curl commands in order to access a time-protected mms stream link, then set up a relay using cvlc (vlc's command line interface) for my own use on an ...