Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
2answers
324 views

Applying a filter to all arguments of cat

I have a list of files on a server, let's say matching the pattern http://example.com/abcd-{0..99}.zip. I want to download, then decompress all these files (they're just zipped text, with one file in ...
5
votes
4answers
8k views

awk / sed to print only up to the underscore character

How can I use awk or sed to print a string only up to the first underscore character? Before: host100_044 2 host101_045 2 host102_046 2 After: host100 host101 host102
0
votes
2answers
437 views

bash: ./wls1036_solaris32.bin: Invalid argument

Having some experience in ubuntu, I installed solaris 11g recently to work on WebLogic. I've downloaded wls1036_solaris32.bin file. When I run ./wls1036_solaris32.bin in the terminal, I'm getting ...
0
votes
1answer
308 views

how to extract string from text using shell script

i have the following text A shell script is a (script) written for "the shell", or command line interpreter, of an operating system. The shell is [often] considered a "simple" domain-specific ...
0
votes
1answer
4k views

Create a tar and splitting it into multiple archives then putting them back together

I am using the following for creating the tgz files: tar zcf - /usr/folder | split -b 30720m - /usr/archive.tgz Now I get three files: archive.tgzaa, archive.tgzab and archive.tgzac So again I ...
0
votes
2answers
380 views

sound detection accessing device node directly

I am attempting to invoke a bash action triggered by audio input. A very simple sound detection sensor (no record) with adjustable threshold utilizing a pc's onboard audio chipset and audio microphone ...
0
votes
1answer
2k views

Expect script inside bash script optional statement

Using: CentOS 6.2 BASH shell My script is something along the lines of #!/bin/bash INSTALL_PATH="Enter install path" CR="\n" /bin/su root -c "/usr/bin/expect << EOF spawn name.run expect ...
0
votes
2answers
60 views

Has Anyone Made a Program to Manage Scripts (Non-CM)? Recommendations?

I find myself often writing shell scripts in Linux and losing track of them over time. What I would love is a program that stores a copy of the script, along with a descriptive note I write at the ...
1
vote
1answer
279 views

OS X mdls command gives “null” in output

I have bash script that utilizes the Mac based mdls command in a shell script to generate a metadata report for media files. When the script works the output looks like this: 1) [./test1.mov] - ...
0
votes
1answer
485 views

Replace text with text from another file in a script?

I want to replace 5 rows of text in a file with the text of another file in my script, I know that running vim I can do :45,50d :r replacement.txt to delete 5 rows and then insert the entire file, ...
0
votes
2answers
51 views

Cygwin: Can I automatically change wa-foo-go to smart_wa_foo_go by only typing wa-foo-go?

When I type: $ ./somescript.sh <file-script-test> wa-foo-go` I want it to change that automatically so that it thinks I typed: $ ./somescript.sh <file-script-test> smart_wa_foo_go ...
0
votes
3answers
82 views

Alias to add .mylongwebsiteaddress to end of lines in cygwin

I have a server called someserver and a website called mylongwebsiteaddress.com. Basically I always type $./somecommand.sh someserver.mylongwebsiteaddress.com in cygwin when doing updates to servers. ...
2
votes
5answers
869 views

Truncate file in a pipe

Is there a simple way to truncate a file in a pipe? Specifically, I want to chop of the last four bytes of a file before feeding it into another process. Ideally, I'd be able to write something like: ...
1
vote
1answer
796 views

Detecting audio playing in a bash script

Is there a way to detect if any sound is playing (using a bash script)? (I'm on Ubuntu 11.10 using pulseaudio.) I plan on using it in an indicator to visually remind me sound is playing while the ...
0
votes
1answer
1k views

Why does my bash script not work? (“command not found”)

I wrote a very simple script that looks like that: $ cat pack.sh #!/bin/bash cd log rm development.log cd .. tar zcvf my_tar_ball.tar.gz * But, it doesn't work: $ pack.sh pack.sh: command not ...
0
votes
1answer
542 views

Best floating point solution for bash script?

I use bash calculator for floating point calculations and I have to use input redirection and backtick (`) symbol in scripts. As normal bracket $[math operation] and expr doesn't support float ...
0
votes
1answer
116 views

Optimize regex formula for checking filenames

I'm working on a regex formula that will check if the supplied file for processing has either of the following formats: SN1234_filename.pdf SN1234_filename.pdf.zip This is what I have right now: ...
1
vote
4answers
469 views

How to extract two numbers from two strings and calculate the difference in Bash?

I have a text file which contains (among others) the following lines: {chapter}{{1}Einleitung}{27}{chapter.1} {chapter}{{2}Grundlagen}{35}{chapter.2} How can I get the 2 lines from this text ...
0
votes
2answers
131 views

How to change one letter in a selected line of a file

My file contains lines like this: link type="text/css" rel="stylesheet" href="https://teststore.myproduct.com/gwtstore.css" link type="text/css" rel="stylesheet" ...
1
vote
2answers
435 views

Have a script execute a command randomly every now and then

I have a script which I am scheduling to run daily with Cron. However I want a certain section of the script to only run randomly occasionally, with a certain probability of executing on any given ...
15
votes
2answers
20k views

How do I enter a literal tab character in a bash shell?

For example, I wanted to use the sort utility with the -t option to specify tab separators, but sort -t "\t" doesn't work.
1
vote
1answer
2k views

Cannot resize tmux pane from bash script

Background and Problem: I have created a tmux script to open a few windows. It works great but then I wanted to place a vertically split pane on one window and resize it to 5 characters tall. I ...
3
votes
5answers
886 views

Convert string “1-5” into array of numbers in bash

What is the best approach to convert the string containing the range of numbers into numbers itself? This format is used for example in defining the range of pages to print. I define, I want to print ...
0
votes
1answer
237 views

Authenticate connection to remote repository before committing files

All, I have an app (using shell script) that automates the process of committing to svn , generating svn info and emailing it. But every now and then I get the following Authentication realm: < ...
1
vote
1answer
1k 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
234 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
248 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
651 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
858 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
4k 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
599 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 ...
11
votes
3answers
12k 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
984 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
4k 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
278 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
404 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.
3
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
314 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
32 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
727 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 ...
9
votes
4answers
8k 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
3answers
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 ...
3
votes
2answers
2k 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
738 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
274 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 ...
1
vote
1answer
4k 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
200 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
6k 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