Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

2
votes
1answer
53 views

sed regex for capture group between delimeters

I have a two line file that I'm trying to get some info out of for a bash script using sed. # File Comment PrefixForInformation {information to be captured} I need to get the information between ...
0
votes
4answers
37 views

How do i write a script to run only if another script has run more recently?

I am attempting to write two scripts. But i run into problems when i try to prevent either one of them from running twice in a row. For example, i have script1 and script2. i want to be able to run ...
3
votes
3answers
47 views

query r.e running for loop scripts in parallel

I have the following in a shell script: for file in $local_dir/myfile.log.*; do file_name=$(basename $file); server_name=$(echo $file_name | cut -f 3 -d '.'); ...
1
vote
1answer
62 views

How can I make this deploy/init run as a non root user?

I have init script which should run as non root user. How can I make it? Ubuntu 12.04 #!/bin/sh DEPLOY_BIN=/usr/share/deploy/bin PID_FILE=/var/run/deploy.pid ...
1
vote
4answers
120 views

How to get the last five business days in a Unix shell script using a `for` loop?

The following script: BUSSINESS_DATE=`date -d "-2 day" +"%Y%m%d"` for (( c=0; c<5 ; c++ )) do WEEKDAY=`date --date="$BUSINESS_DATE -$c day" +%w` if [ $WEEKDAY == "0" ] then ...
0
votes
1answer
31 views

error in script for number of occurences count [duplicate]

I have written a small script to count number of occurrences of logs in megabyte from a particular file following is my code #!/bin/sh count=1 while read line do found=$( grep M $line ) ...
0
votes
1answer
42 views

error in script for counting number of occurences [duplicate]

#!/bin/sh count=1 while read line do found=$( grep M $line ) if [ "$found" ]; then echo $count")" $line >> filesave.txt fi count=$((count+1)) done < log1.txt but i am getting ...
1
vote
0answers
58 views

error in count script for number of occurences

I have written a small script to count number of occurrences of logs in a particular file. The following is my code: #!/bin/sh count=1 while read line do found=$( grep M $line ) OCCURENCE=$( ...
5
votes
4answers
833 views

How to extract IP numbers from a text file?

How could I extract just IP numbers from a file formatted like what follows? test-Zookeeper2-Z1-solr1006 10.15.5.226 10.15.6.103 test-Zookeeper2-Z2-solr1006 10.15.5.92 test-Zookeeper3-Z1-solr1006 ...
1
vote
0answers
37 views

Change events order in bash script that writes to crontab

Coming from the solution on this post I have made a few changes to the original script but output is not like it should be. Below is the script as I have right now: #!/bin/bash add=$1 ...
2
votes
3answers
141 views

Read each directory and perform actions in Bash script

I have this directory structure at /var/sync: # tree -d /var/sync/ /var/sync/ ├── sync_bi │   ├── replicator => Replicator.php │ sync.php ├── sync_pfizer │   ├── replicator => Replicator.php ...
1
vote
1answer
57 views

tail: illegal option — -53\r error while using head and tail on same file in single script

I am using a=`head -1 Rt.in` to get first value from my file and I am saving it as a variable then I am using same variable to tail -$a to tail last lines from my input. But it is giving an ...
1
vote
1answer
37 views

Remove tag and contents based on child tag and add a new content - Shellscript xml

Can anyone please guilde me with this. I am trying to locate a particular tag, based on it child's contents and remove the parent tag and contents and add a new contents, but cant find an answer. ...
1
vote
1answer
17 views

How do I write a script to automatically compile and install all Moksha modules?

I have this repository cloned on my Sabayon machine, what I would like to do is write a script that will change into each directory of this repo (just the top-level directories, not directories inside ...
3
votes
3answers
439 views

How do I pipe the output of tar through mv?

A previous question of mine asked how to pipe downloaded files through tar, now I would like to know how to pipe the output of tar through mv. See I have this command at the moment: wget -c ...
4
votes
4answers
150 views

Delete all but the most recent n file for each group of files that share the same prefix in a directory

My question is a bit different from some older questions simply asking for "deleting all but the most recent n files in a directory". I have a directory that contains different 'groups' of files ...
0
votes
2answers
63 views

grep between two lines with specified string [duplicate]

I have this simple plat file (file.txt) a43 test1 abc cvb bnm test2 test1 def ijk xyz test2 kfo I need all lines between test1 and test2 in two forms, the firte one create two new files like ...
1
vote
1answer
55 views

Pass a value for an input prompt

I do unzip my.zip and if files already exists it asks replace myfile.ext [y]es, [n]o, [A]ll, [N]one, [r]ename: How can I force input for when the command prompts for input? I am aware unzip may have ...
1
vote
2answers
109 views

Bash script not running as expected

I'm trying to get the script below to take the connection uuid passed to it (by networkmanager), compare it against a list of uuids for my home connections (both physical and VPN) and run certain ...
2
votes
2answers
33 views

How do I write the output of Portage to a txt file?

I would like to be able to write the output of Portage commands, along with other commands, that I perform in tty (that is, the screen-wide terminals started with Ctrl+Alt+Fn where n represents an ...
1
vote
4answers
95 views

Find and delete all same files (by name) between 2 directories

I want to find all files in dir1 having corresponding same file names in dir2, and delete them from dir1. For example: dir1: first.txt second.txt dir2: third.txt first.txt So I want to remove from ...
1
vote
1answer
47 views

Merge records depending on common columns and specify the values which are uncommon in the last column as comma separated

I need to merge records depending on first three common columns and place the values which are uncommon in the last column as comma separated . I have a requirement to do the following- InputFile : ...
1
vote
3answers
69 views

Bash script to monitor server security?

I am using a shared server at HG and I want to automate a bash script that will run hourly once and notify me to my gmail account with details of authorized/non-authorized users who have logged into ...
2
votes
2answers
50 views

Find and replace all same files between 2 directories

I want to find all files in dir1 having corresponding same file names in dir2, and replace them with the files from dir2. For example: dir1: first.txt second.txt dir2: third.txt first.txt So I ...
1
vote
1answer
58 views

sed, getting an error:sed: unterminated {

I'm using below sed command sed -n '\|<tag>|{:n; \|</tag>|!{N;bn}; y|\n| |;p }' test.xml OUTPUT: <tag> <name>jolly</name> <class>2nd</class> ...
1
vote
4answers
57 views

Bash script to make a list

How do I write a bash script that makes lists by by selecting a column of a spreadsheet which is in csv format? If I have csv files that have these contents: [user]$ cat list1.csv ...
-3
votes
1answer
34 views

Can read take more than a single variable?

I want to have someone input two separate numbers for example: echo "Type two different numbers. For example: 1 3" then take the two separate numbers they type and put them into their own ...
1
vote
2answers
53 views

Unzipping file with exclamation mark from command line in bash script

I'm trying to do a simple script that unzips a zip file which has an exclamation mark in its name: #!/bin/bash UNZIP='/usr/bin/unzip' CUT="/usr/bin/cut" GREP="/usr/bin/grep" FILENAME="test" ...
6
votes
5answers
2k views

Passing root password safely in a shell script

I always boot up my GNU/Linux laptop in console mode. But sometimes I need to bring up the GUI mode. it always requires entering the root password. So I wrote the following script "gogui.sh" and put ...
-1
votes
3answers
86 views

In the Linux Terminal, is there a difference between “bash foo.sh” and “./foo.sh”

This might be a silly question to ask, but as I am new to Linux and am trying to learn as much as I can about it, I'm going to ask anyway. After all, "The more you know!" When executing a bash ...
2
votes
1answer
76 views

tr -c '[a-zA-Z]' '\n' not replacing all complement characters

Writting a script I wanted to replace all characters except alpha ([a-zA-Z]) with a line break. By definition, when using -c flag (set complement) tr is supposed to replace all characters that are not ...
-1
votes
2answers
50 views

First match if we are on the first line of input, if so print the whole line, else print the first word followed by a comma

for eg: CREATE TABLE MWWDATA.ACK997 ( AKTYPE CHAR(2) DEFAULT '' NOT NULL , AKNUM CHAR(9) DEFAULT '' NOT NULL ); CREATE TABLE MWWDATA.APREIDEXC ( EMPLID NUMBER(15, 0) DEFAULT NULL ); ...
0
votes
3answers
33 views

i want to print the line which starts with a paricular word and in the rest records print only 1st field

for eg: CREATE TABLE MWWDATA."VTCat02" ( "ID" NUMBER(10) DEFAULT NULL , "Cat" VARCHAR2(255) DEFAULT NULL , "Style_Code" VARCHAR2(255) DEFAULT NULL , "Vendor_Style_#" VARCHAR2(255) ...
0
votes
1answer
37 views

Manage-scripts in an open-source program

A strange thing happened when I try to use an open-source after GNU building , here it is : No error presents in ./configure ./make ./make install When I try to use it , there is some vars in this ...
0
votes
1answer
108 views

Shell script to process service restart procedure

We're running a 3rd party TTY service on our servers, to support some thin clients manufactured by the 3rd party. From time to time, connection to a thin client can get locked up. Procedure is to ...
3
votes
3answers
190 views

How do I download all files listed in an array?

I want to download all files in this GitHub directory to /usr/share/enlightenment/data/config. I have this script: L=('e.cfg' 'e_randr.cfg' 'exehist.cfg' 'module.battery.cfg' 'module.clock.cfg' ...
2
votes
2answers
128 views

Refactor code using sed

How do I write a sed script the rearranges/refactors a string of characters of a file? The contents of my file are: for(int i=0; i<old(a, 10); i++) { sum += old(c*c, i*a) } ...
1
vote
1answer
70 views

Filename expansion for expect script within bash

I have the following bash script with an embedded expect script: #!/bin/bash if [ ! $# == 2 ] then echo "Usage: $0 os_base_version sn_version" exit fi if [ -e ...
5
votes
3answers
414 views

Weird float rounding behavior with printf

I've read some answers on this site and found the printf rounding desirable. However when I used it in practice, a subtle bug led me to the following behavior: $ echo 197.5 | xargs printf '%.0f' 198 ...
4
votes
3answers
183 views

Linux find-command skips a directory

I have certain network share folders mounted in the /media directory. I want to make sure that when I do something like sudo find / -name foo it should always skip the /media directory. I don't want ...
0
votes
1answer
133 views

how to execute a shell script from any directory

I wrote a simple script with the extension .sh in my home directory that I can just run right in my home directory, but I want to run the script from every directory that I am in. What should I do? ...
3
votes
1answer
74 views

Listing the files from the nested zip file without extracing

I have nested zip files and i need to list the file names without extracting in the temp location. Using shell script. Please let me know if we have any work around Expample : Zip1 text1 ...
2
votes
2answers
161 views

How do I get ~/.bashrc to execute all scripts in my ~/Shell directory using a loop?

I have shell scripts in my ~/Shell directory that I want to be run whenever Bash is started up as my usual user account. So what I have done is added the following to ~/.bashrc: for i in `find ...
2
votes
0answers
74 views

Unable to start ZNC as a service

Firstly, this is the exact same question as found here, but the given solutions did not work in my situation. Background I am running a CentOS 6 VPS and I want to run a ZNC bouncer on it. I ...
1
vote
1answer
43 views

Help with writing script that logs in and out of ssh server

This is a bit long, but please bear with me. I am currently doing a lot of work with the shell, and I need help writing some specific shell-script. I have basic shell scripting skills, at least enough ...
1
vote
0answers
36 views

shell script to join 2 files on basis of 2 columns and if a match found then write some fields

abc.csv TBL_NAME,SANDBOX_NAME,SCRIPT_NAME ccti_prod_attdnl_ext,abs_ext,101_ext_table.m_diag.pset ccti_prod_attdnl_ext,abs_ids,101_ext_table.m_diag.pset xyz.csv ...
1
vote
1answer
28 views

Abortable task on startup on Ubuntu 14.04

I have a VM that needs to boot up, perform a specific task, and then shut itself down. It also needs to be possible to abort the special startup sequence to get the "regular" bootup behaviour, i.e. ...
1
vote
2answers
98 views

How do I pipe the files downloaded with wget through tar?

I would like to pipe tarballs (.tar.gz files in this case) I download with GNU Wget (wget) through tar -xzf (to decompress them, if this is unclear) but I don't know how. I have tried: wget -q -O- ...
2
votes
1answer
53 views

Init scripts. Distinction of booting and starting activity

I have some script that runs and shuts down some service placed into /etc/init.d. It has symbolic link into /etc/rc5.d added with chkconfig for autolaunch on booting. Hence it starts on boot and can ...
2
votes
1answer
44 views

Errors with git alias shell command

I'm using bash version 4.1.2(1)-release (x86_64-redhat-linux-gnu) on cygwin with git 1.7.1. I wanted to make an alias for a command that needed to use the input argument twice. Following these ...