Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
1answer
1k views

Save result of a grep -c into a shell variable

How can I store the result of grep -c as an integer in a shell variable? This: check=sudo virsh list |egrep -c '\b[0-9]{2}\b' only gives me the number of matches and prints it on screen whereas ...
3
votes
2answers
116 views

Append dir to PATH

I'm trying to localy add a dir to the global $PATH variable. I added the following to my .bashrc. export PATH=$PATH:$VRS/bin But PATH seems to get concatenated to itself over & over every time ...
2
votes
2answers
471 views

Prefix to each output of a command on runtime

I am trying to make a modular script. I have several scripts/commands which are called from a single script. I want to prefix the output of each separate command. Examle: My files are allcommands.sh ...
0
votes
1answer
247 views

Getting error while executing shell script in Cygwin?

I have done a script (bash) and kept the same in E:\Ping folder of my local Windows 7 m/c, and I am trying to run the same through Cygwin. I'm getting a bash: sh : command not found error. What is ...
1
vote
1answer
843 views

Removing files older then 1 month, but leave one file per month

I try to script something similar to Removing files older then 1 month, but leave files created at the 1st day of the month. The difference is that I need one file per month. I am using the script ...
-1
votes
1answer
168 views

Making a user creation script for web server [closed]

Ok, so I'm building a webserver and MySQL server from scratch... Server A is going to have Apache and PHP Server B is going to have MySQL Both servers are running Ubuntu 12.04 LTS server I plan on ...
-1
votes
1answer
199 views

while loop in bash until file size does not change [closed]

I'm trying to do the following while loop using a bash script file_size = 0 temp_size = 1 output_file while (file_size != temp_size) temp_size = file_size download file append to ...
2
votes
3answers
215 views

Shell script not running as by “./” but it runs by “sh”

I am running a script on arm target board as a super user, i.e., as a root user. But the script is not executing if i run it with following syntax root@freescale$ ./Script.sh -sh: ./Script.sh: ...
0
votes
3answers
120 views

Possible to use more than one core with sed and bash?

I am looking to use more than one core when replacing values with sed in bash, is this possible?
0
votes
3answers
1k views

How do I parse a line thorugh a file in bash

I am very new to shell scripting I had a small query regarding the file parsing. So, here's what I am trying to do: I run an svn merge command, and genaratea conflict file my conflict file is ...
0
votes
2answers
404 views

Trying to find any home directory that is writable by anyone

I am trying to locate any user home directories and their files that are writable by anyone. I wrote this: find /home -type d -perm -200 | grep . || echo no world-writable directories here ...
0
votes
1answer
169 views

Batch processing in Linux?

What kind of script I need to run a batch on Linux? I have to launch this line php magmi.cli.php -profile=FINALE -mode=create -CSV:filename="path/to/file01.csv" 40 times for 40 different CSV files ...
0
votes
2answers
506 views

Mac OS X login script for specific user

I need to be able to run a bash script every time a specific user logs in. The solution here is for all users. Is there any way to specify the user, and if not is there a way for the bash script to ...
1
vote
2answers
350 views

Why does xmessage report that user clicked 'x' without displaying message when run from cron?

I have the script below, which seem to work perfectly when run from the commandline with /root/.scripts/peter-laptop-backup-launcher.sh daily (it displays an xmessage asking what I want to do), but ...
0
votes
3answers
276 views

Is there any way to encapsulate bash functions?

I'm writing a simple script script.bash that is supposed to export some variables environment, to use it in my current session I have to source it $ . script.bash script.bash function fun1() { ...
3
votes
2answers
116 views

Found a script on my cron.monthly, i am wondering what's it doing?

I am new to bash-programming, sorry if this might be a kind of stupid question. I found a script on my server and i am trying to understand every line: #!/bin/sh # # man-db cron weekly set -e if ! ...
3
votes
1answer
476 views

Parse multiple HTML to text and rename as parent Directory

In a directory there are many folders .html inside, I would like all HTML parsed as new .txt with the name of the parent directory. Example1/ Index.html>Example1.txt Example2/ ...
1
vote
1answer
171 views

Bash script template to copy files to predefined destination folders

I need an interactive bash script template to copy files to predefined destination folders. If possible, when prompted for user input tab completion would be enabled for a predefined source directory. ...
1
vote
1answer
259 views

qsub -hold_jid -afterok loop not starting

I am trying to run a series of jobs submitted to the cluster, one after the other, by suplpying the following .sh script: Annotation_Loop.sh : #!/bin/bash job=`qsub run_IntersectBed_1.sh 0` for i ...
0
votes
3answers
231 views

win-bash won't detect root drives?

I'm using the windows port of bash known as win-bash, and based on what it says about paths: One important difference is the handling of drives: cygwin uses its installation directory as root ...
1
vote
1answer
74 views

Writing a script to tell which users are currently typing? [closed]

I'm working on a lab for a cyber-security class and need to find out when certain users are communicating with each other (through named pipes). The users use: python gameProgram.py And then that ...
1
vote
1answer
531 views

kill process on external script run as a service

I've setup a linux (CentOS) service to run a script that runs in the backgroud (daemon /home/user/testftp.sh &) or in the context of the start and stop service: # Source function library. . ...
2
votes
1answer
118 views

How to get the result from bash auto-completion as a string?

What I'm looking for is not how to add autcompletion in bash for another program, but a way to get the result of what would have happened in bash to a string, basically: autocomplete "/etc/apa" ...
0
votes
1answer
21 views

What's the syntax to open a Tracker window from the command line in Haiku?

I've tried these: Tracker /path Tracker /path/ /path /path/ ...but no dice (the former two open Tracker's preferences window and the latter complain that /path is a directory.) What should I do? ...
-2
votes
1answer
1k views

Calculate % difference and file sizes between two files

We have two zip files and would like to compare them. We're also interested in calculating the percentage difference between them and the file size. Is there a tool that can do this quickly?
7
votes
2answers
1k views

bash completion for filename patterns or directories

I'm trying to get a bash completion script set up and having some trouble. I would like to set it up so the completions listed are either files matching a particular extension, or directories (which ...
1
vote
1answer
46 views

UNIX Scripting Possibilities

Need a small help to understand if a task can be accomplished using UNIX script. Situation: Symantec Endpoint Encryption when installed on Mac, a manual intervention is required where a technician ...
0
votes
1answer
175 views

Automatically name output of montage based on input files

I have a folder with images separated into channels: IMAGE_A_R.jpg IMAGE_A_G.jpg IMAGE_A_B.jpg IMAGE_A_RGB.jpg IMAGE_A1_R.jpg IMAGE_A1_G.jpg IMAGE_A1_B.jpg IMAGE_A1_RGB.jpg IMAGE_B_R.jpg ...
0
votes
3answers
153 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
59 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
2k 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
874 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 ...
0
votes
2answers
892 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
250 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 ...
1
vote
3answers
4k 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
103 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
180 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 ...
2
votes
1answer
6k 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
373 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
92 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
950 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
93 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
208 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
341 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
58 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
265 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
1k 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
309 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
428 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 ...