Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
1answer
1k views

Advanced merge directory tree with cp in Linux

I need to: Copy all of a tree's folders (with all files, including hidden) under /sourcefolder/* preserving user privileges to /destfolder/ If there is a conflict with a file (a file with the same ...
3
votes
3answers
107 views

Why doesn't this script work?

I've been using this bash script: for i in $(ls); do mv $i a$i; done to prepend all filenames in a folder with the letter a. I'm afraid that at some point I'll accidentally use this script in the ...
0
votes
1answer
582 views

My bash script does not find an existing file (into the script's wd) which name I passed as a parameter in a function

I realized a bash script that works on an existing text file located into the same working directory of the script. The script take name of the file to compute through a function parameter. The issue ...
4
votes
1answer
52 views

How to filter output from a command in OS X

I am in need to monitor the the writes from an unknown application to a known directory through creatbyproc.d. I'm going to have to leave this up and running for up to 36 hours which will not be ...
0
votes
1answer
106 views

Bash delete file when variable = x

I'm creating a bash script which reboots the system at each reboot it adds a new line to a text file, I then read the text file before each reboot. Once the variable holding the number of lines ...
4
votes
1answer
355 views

BASH function not escaping control characters

Hey guys I have a function that I'm using to find stuff, but unfortunately anytime I pass it a control character ($intVal or testing : etc) it chokes. I was wondering what the fix was? I can ...
1
vote
1answer
4k views

Howto switch / chage user id witin a bash script to execute commands in the same script?

Is there a way to switch user identity within a script (executed as root as part of an installation process) to execute some commands without calling an external script, then return to root to run ...
2
votes
2answers
339 views

concatenate files including path in header - path contains spaces

I have to concatenate a number of files in a directory structure which contains spaces in the folder names looking like this: ./CH 0000100014/A10/11XT/11xt#001.csv find . -name "*.csv" -type f ...
3
votes
1answer
59 views

Checking pids under all users and re-launching the processes after reboot

Is there a way to check all pids of all users under /home directory, and to run these processes again after a reboot or shutdown? For example, if user1 was running a psybnc and user2 was running an ...
0
votes
2answers
671 views

keep environment when executing in script

I have a bash script that should be executing a number of commands. The commands work fine when entered in a termainal but when I try to execute them from inside the script they don't work, so I ...
0
votes
0answers
217 views

Getting a setting, the chdir value, out of GNU Screen

I've been using screen's chdir command to set a new working directory for new screen windows, more on that later. What I need to do is find out what the setting was before I set it, so that I can set ...
2
votes
1answer
369 views

How to calculate and group the time differences of specified syscalls when running strace

I'm planing to do some web performance testing (to see how much time it's spent for each file), but it could be useful for any application. I exactly know existence and how to use different ...
1
vote
1answer
456 views

Scripting output of a telnet connection

Another whois question, is it possible for me to take the output of a telnet connection to a file. telnet whois.internic.net 43 then I =google.com and get a response. Can I get this to return ...
2
votes
2answers
395 views

Word splitting does not see my quotes

Imagine I have this $ ARGS='"a b" c' $ for arg in "$ARGS"; do echo "$arg"; done "a b" c $ for arg in $ARGS; do echo "$arg"; done "a b" c The result I'm looking to get is $ <???> a b c How ...
8
votes
4answers
5k views

How to truncate file by lines?

I have a large number of file, some of which are very long. I would like to truncate them to a certain size if they are larger by removing the end of the file. But I only want to remove whole lines. ...
0
votes
1answer
158 views

linux bash backgrounding and I/O redirection

I'm having bash backgrounding and file redirection issues. I need to attach to a remote sensor box and record the ascii datastream from that box onto disk files. I'd like to break that datastream ...
0
votes
1answer
241 views

How to quote a command between backticks when shell scripting

The command executed in the following script works: #!/bin/bash -xv REM_DIR="/home/jan/rem-dir" SSHOPTS="-C -c arcfour256 -o "\""ServerAliveInterval 15"\" SSHUSER="jan@example.com" CMD="ssh $SSHOPTS ...
6
votes
2answers
66 views

Process files in a folder that haven't previously been processed

I have a series of files in a directory that I need to carry an action out on using a script. Once the action is done, then I want to keep a log that the file has been processed, so that the next ...
0
votes
3answers
557 views

Customizing BASH output colors?

How do I customize bash colors for command output? For example; I run ls and want directories and files to be a different color. How do I accomplish this? I see that distro's are doing this but I ...
0
votes
2answers
98 views

Showing a stack of ssh connections in terminal

I had this idea for long time and tried several ways to implement, with no luck. Tried to google many times and always finding not quite what is needed. How to do: $ ssh hostA ...
0
votes
1answer
379 views

IP Address dotted decimal to /8 or /16 notation using bash,sed or awk?

I have an input file that contains a list of ip addresses and the ip_counts(some parameter that I use internally.)The file looks somewhat like this. 202.124.127.26 2135869 202.124.127.25 2111217 ...
0
votes
1answer
487 views

How can I create session logs of individual SSH sessions?

Here is what I am looking for: A way to log individual SSH sessions on SunOS. I would like to have the files kept separate based upon the hostname of the device I am SSHing into. I am only using ...
1
vote
2answers
122 views

What's the easiest way to 'cat' groups of files together?

I have files with naming convention of this pattern: bond_7.LEU.CA.1.dat bond_7.LEU.CA.2.dat bond_7.LEU.CA.3.dat bond_12.ALA.CB.1.dat bond_12.ALA.CB.2.dat bond_12.ALA.CB.3.dat ... I want to ...
0
votes
2answers
223 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 ...
3
votes
4answers
4k 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
302 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
273 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
2k 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
286 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
182 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
394 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
77 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
671 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
400 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
875 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
464 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
111 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
377 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
118 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
314 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 ...
10
votes
2answers
9k 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
1k 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
694 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
208 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
690 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
192 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
194 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 ...