Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
3answers
216 views

output the items that showed up 2 times and more

How can I select the ips that showed up 4 times or more , for example here? the input file is 192.168.1.28 192.168.1.100 192.168.1.31 192.168.101.2 192.168.1.31 192.168.11.02 192.168.1.31 ...
1
vote
3answers
65 views

How do I get multiple scripts prompted with an alias in Cygwin?

I want to run one command, then bring up a second, but modify it first before pressing enter on it. (Cygwin) I usually just type it all out like this: svn up 8.0; ./merge.py 8.0 12345 I also have ...
1
vote
1answer
4k views

Removing files older then 1 month, but leave files created at the 1st day of the month

I'm trying to remove some archive files from a folder on a CentOS fileserver with a cronjob. The requirements: Remove files of the last month The .tgz-file of the first day of the month should be ...
1
vote
3answers
2k views

How to define alias for command which will be available in shell script?

Here is a part of my .bashrc alias my_command="my_command -1 -2 -3" and its my shell script #!/bin/sh my_command blah blah blah It occurs into error ./aa: line 2: my_command: command not found ...
2
votes
2answers
1k views

ZSH: Read command fails within bash function “read:1: -p: no coprocess”

Edit: Seems to work within bash. It appears the problem is related to zsh. If there is a better site to post this issue on let me know. I am writing a simple script that creates a series of ...
2
votes
1answer
381 views

Bash script: “[[: not found”

This is my code: #!/bin/bash if [[ -d ~/viwiki ]]; then cd ~/viwiki else mkdir ~/viwiki cd ~/viwiki fi if ! [[ -d ./log ]]; then mkdir log mkdir log/log mkdir "log/wget" elif ! [[ -d ./log/log ...
2
votes
3answers
8k views

Bash: Find and replace text strings

I figured this would be easy, but I'm overlooking something simple: I have a text file called test. It contains, for example, the string Alfred Hitchcock. I want to replace this with Alfred\ ...
0
votes
1answer
129 views

How can I check the contents of folders for certain files?

How would I go about writing a script to loop through every folder on a hard drive, find any video files, extract them to the root of the hard drive, and then delete everything else?
3
votes
2answers
243 views

Is a subshell executed with a here string?

I'm trying to better organise a bash script as part of a re-write/re-organisation and am wondering what "best practice" is in the following situation: ymd=`echo "${NOEXT}" | egrep -o -m 1 ...
6
votes
1answer
12k views

How can I compare a variable to a text string, rather than integer, in an if/else statement?

In the process of writing a shell script, I ran into an issue with the following if/else statement that falls somewhere in the middle of the script: if [ $act -eq "add" ] then read - "add or ...
8
votes
1answer
610 views

How to make sed omit not matching lines?

In the following example, sed matches lines starting with an a or a c and prints the first character of that line (a or c): $ echo "ag bh ci dj ek fl" | sed 's/\(a\|c\)./\1/' # Matches lines starting ...
0
votes
2answers
101 views

For loop with conditions

I have a script that adds user on many server. Since I'm adding on many server(s) I am using for loop. Below are the output when user is successfully added. 0,22529,User added. If the user is not ...
5
votes
5answers
1k views

How to move all sibling folders into one folder?

I apologize that this seems like such a dumb question, but I can't afford to screw it up. I have a bunch of folders like so: /users/me/foo/oops1 /users/me/foo/oops2 ...
1
vote
3answers
96 views

Find a file in the CWD or any of its parents

I'm trying to create aliases for commands I'm typing a lot. Because I'm working on a big project built on Laravel I need to use the command line tool artisan fairly often. However, I don't often want ...
1
vote
1answer
248 views

Cygwin browser script error

I use multiple browsers, and I created a bash script that checks to see which browser is open and opens web pages in whatever browser is already open. I use Windows 7, so I run this script using ...
0
votes
2answers
409 views

Root set environment variables

I have a small bash script which downloads a critical file, opens an SFPT connection, puts the file and closes the connection. As you can imagine, my script has some username and password information ...
1
vote
2answers
59 views

Outputting less into a file

while on bash, i tried to delete the 3 last columns of a file using: head -n -3 file > file but the file comes out empty. I can walkaround it but I would like to know what causes that. Thanks a ...
0
votes
1answer
436 views

Determining if an argument looks like a valid path

I'm writing a bash script that needs to perform some operation on an argument which is a path The path may or may not correspond to an existing file on the user's system, so I'd like to test whether ...
0
votes
1answer
31 views

Environment auto-install

When I work, I often have to switch computers or virtual machines which means that every time I switch, I have to set up my (Linux) environment again. My question is the following : Is there a tool ...
0
votes
1answer
2k views

Can't edit '/etc/network/interfaces' file through bash script in Ubuntu [duplicate]

Possible Duplicate: sudo permission denied I got need to edit /etc/network/interfaces through bash script, I am doing something like below... sudo echo something > ...
0
votes
1answer
405 views

bash getopts, parsing ranges

What would the best approach be to parse argument value ranges using getopts? As an example: $ script.sh -r2-4,6,8-10 In my script I would then have an array with the values 2, 3, 4, 6, 8, 9 and ...
3
votes
1answer
659 views

Script-specific autocomplete in shell

I create a lot of little scripts to help me in my every day life. I would like to provide auto-complete for them, specially that I intend to share them with people. Now, I know I can create ...
-1
votes
2answers
2k views

Execute multiple commands in one line inside unix shellscript

The question is somewhat related to the question asked here, http://stackoverflow.com/questions/5130847/shell-multiple-commands-in-one-line, but the difference is, I need to execute the whole commands ...
3
votes
3answers
69 views

merge pieces of file together

I have a directory tree of files I need to loop through and reformat the lines. can I do this with sed with some combination of find? for each file, I'll need to adjust the text in the file from ...
1
vote
2answers
1k views

Assign values or string to a variable in linux scripting

I am trying to assign the output of the basename command of a file to the variable "filename". paths is a file that contains the path location, e.g /root/home/david/mynote $FILE is = mynote. grep is ...
0
votes
1answer
41 views

Run a specific command from a directory

I have a bash script where I need to run an init utility within a directory with a configuration file defined. I don't think it's possible to explicitly tell the utility to run the file as an ...
0
votes
2answers
3k views

Automounting SD card when inserted in Ubuntu

I am trying to write a BASH script that automounts an SD card once it is inserted in the card reader, then move all pictures to a folder in the HDD and renaming each file to the date and time the ...
1
vote
2answers
350 views

Revising a bash script - Invoking a change of prompt color via a temporary file

I am wondering why the following script won't work: #!/bin/bash read -p 'First lets write PROMPT.SH' echo '#!/bin/bash'>prompt.sh echo "export PS1='\e[1;31m\]\u@\h \W\$\e[0m\] '">>prompt.sh ...
8
votes
2answers
2k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
0
votes
0answers
113 views

gnome-terminal flag sh

I'm extremely new to linux, so i kinda need some tutoring... been teaching myself some scripting. Most of the stuff I just copy of sites. what baffles me is the little flags that appear in this line: ...
0
votes
1answer
232 views

output redirection not happening completely

I am running the following command on ubuntu 12.04 bash shell: hping3 -S -p 80 -c 30 www.google.com >> outputfile.txt But the problem is that this leaves some lines in the end and doesn't ...
1
vote
3answers
2k views

How could I make a bash script to execute apt-get?

I'm trying to automatize some configurations I have with bash script, I've never done this before so I tried with something easy like a Hello World! and everything works just fine, but then I tried ...
1
vote
3answers
2k views

Run shell script on Linux box from a shortcut/app in Android?

I have an Ubuntu box which runs XBMC, which crashes occasionally. Since I have no keyboard connected,I have to SSH in, kill xinit, then restart it. I was wondering if there's an elegant way of doing ...
0
votes
1answer
2k 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
919 views

My bash script does not find an existing file

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
60 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
116 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
498 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 ...
2
votes
1answer
6k 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
394 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
64 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
1k 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
277 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
546 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
563 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
605 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 ...
11
votes
4answers
8k 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
182 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
346 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 ...