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

learn more… | top users | synonyms (2)

5
votes
1answer
152 views

ifconfig -a in a shell script

I am writing a shell script to start my network in my virtual machine on boot, since it does not do this right away for some reason with a snapshot of a virtual machine. Since the eth device starts ...
5
votes
2answers
114 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
2
votes
2answers
154 views

Store all dates in a given date range into a variable

I want to store all possible dates between two user input dates. The input will be as like 20140605 and 20140830. I want to store every date between the given dates into a variable using a loop so ...
1
vote
4answers
81 views

Extracting a string from fdisk command

I want to write a shell script, which will run fdisk -l and extract a string /dev/sdbn from the output of fdisk -l. Using extracted word I want to mount it to /mnt. For Example: Disk identifier: ...
1
vote
1answer
47 views

Bash Script Display Remote Screen Session to User

I'm kind of new to bash scripting and I'm having trouble figuring out how to accomplish this. I'm working on a script that is designed to backup and manage a java application that runs within a ...
0
votes
1answer
41 views

Using getopts to parse options after a non-option argument

I have a bash script as below in a file nepleaks_upd.sh, that I want to run as ./nepleaks_upd.sh bootstrap --branch off. Couldn't make it to take --branch , but what it works with is ./nepleaks_upd.sh ...
2
votes
2answers
55 views

Removing lines with a single common field

I have a tab separated file that looks like this: 123 some text 123 some different text 334 some other text 341 more text and I want to do two things. One is to order everything numerically ...
4
votes
3answers
185 views

How can I delete a trailing newline in bash?

I'm looking for something that behaves like Perl's chomp. I'm looking for a command that simply prints its input, minus the last character if it's a newline: $ printf "one\ntwo\n" | ...
4
votes
3answers
236 views

Which regular expression methods to validate input could be used in shell scripting?

#!/bin/sh re="\/$" if [ $1 =~ $re ]; then echo "${ATTENTION_PREFIX}$1 DIRECTORY MAY NOT CONTAIN A \"/\" OR LITERAL SLASH!${ATTENTION_POSTFIX}" exit 1 fi Executing sudo file.sh ...
1
vote
2answers
62 views

Email using shell script

Is there a possibility to add multiple e-mails to a single variable so that when the shell script is run, it sends a mail to all the specified emails?
3
votes
1answer
47 views

Using inotify to monitor a directory but not working 100%

I have written a bash script to monitor a particular directory /root/secondfolder/: #!/bin/sh while inotifywait -mr -e close_write "/root/secondfolder/" do echo "close_write" done When I ...
2
votes
1answer
68 views

Accumulate Filename in a Log file using shell script

I have files with their names as ABC_-_123321.20140505_-_161500.CSV ABC_-_654145.20140506_-_135020.CSV String_-_SerialID.Date_-_Time.CSV StartDate, StartTime, EndDate and EndTime are given as ...
0
votes
2answers
61 views

Convert json mapping object to managed csv row using bash script

I have json mapping under properties key as below in a file Customer.json, { "customer": { "properties": { "customerId": { "type": "string", ...
1
vote
1answer
41 views

How to get find -exec to call a shell script?

Taking from the last answer (by im3r3k) here: How do I recursively shred an entire directory tree? I'm trying to get the find command to call a shell script as described. So far I've tried: find ...
0
votes
3answers
56 views

bash script calling itself with different arguments

I just can not get it right. Script takes two arguments, target and command. Valid targets are specified within an array. If target is 'all', script should iterate through all targets. #!/bin/bash # ...
1
vote
2answers
51 views

sh + how to use array in sh script in order to print all values in array

I want to use arrays in my sh script. My target is to create an array with the values a b c and print all values in the array. I succeeded to print each array, but I failed to print all values in ...
2
votes
2answers
126 views

Printing lines with similar text together

I am currently working on analyzing the performance of an application. I've starting by looking at the logs generated by our application and identifying the business logic tasks that are taking more ...
2
votes
1answer
43 views

Displays and their relative position in a shell script

I want to get information about the displays, something like xrandr, but with more info. I want to know their position. So if I have two or more displays connected I want to know how they are ...
2
votes
1answer
37 views

Extracting lines around keys from a file

I have a large file with around 15 million lines. The odd lines contains the keys (but not only the keys) and the even lines are the data. That is, the file is something like: WRTZ Tyrosine ...
2
votes
0answers
39 views

Scripts cannot run simultaneously on startup

I want two scripts (Server_drive, Server_video_boot) running on startup, but there is conflict between them. Specifically, there is always running the script with the lower priority. I tried with many ...
2
votes
0answers
28 views

Creating multicast join for tcpdump captures

I want to write a linux shell script which will capture specific multicast traffic. Specific as in, I want to create a pcap file that has all the traffic for one specific multicast group/port. Here ...
4
votes
1answer
82 views

Executing commands with ssh and shell script using variables on a remote machine

I'd like to execute a command and script located on a remote machine with a script on a local machine. I know it's possible to execute these kind of commands with ssh, so I made: #!/bin/bash ssh ...
1
vote
1answer
42 views

command not found in shell script

Please tell me why I couldn't print variable value. # chmod 777 chkscript.sh # ./chkscript.sh chkscript.sh file content variable = "This is variable" echo "$variable" echo "Hello World " ...
0
votes
1answer
21 views

How to complete a script to move selective files and directories in a filesystem to another (dump) path in a different filesystem?

1) There is a filesystem, say FS1, having below files and directories : drwx------ 2 256 Jun 20 05:47 recovery_scripts drwx------ 2 256 Jun 20 05:47 sqllib -rw------- 1 ...
5
votes
1answer
36 views

Ctrl-C is ignored by pppd when put in a shell script

I'm trying to connect to GPRS network through a serial port connected GSM modem. When I call /usr/sbin/pppd call <peer_name> from the command line, it correctly receives and handles Ctrl+C from ...
4
votes
1answer
46 views

Default to “Execute” when double-clicking on a shell script in PCManFM

Is it possible to get an executable to execute by default? What I mean is this. I have an .sh file, which if I click on twice, it will show me this: If I then click Execute, it does the right ...
6
votes
1answer
55 views

BASH return to main function

I have a BASH script that calls a function, which calls other functions: #!/bin/bash function foo { function bar { # do something } bar } foo How can I return from bar ...
3
votes
1answer
47 views

Launch RDP silently?

I currently use the following command to launch an RDP session which works fine: rds@rds:~/Downloads/FreeRDP$ xfreerdp /v:farm.company.com /d:company.com /g:rds.company.com /f /u:username /p: At ...
1
vote
0answers
23 views

Open to specific gvim tabs

I have a working environment that I'd like to save via a script. -EDIT: I don't need to save it's state, I just want my script to define it. Though saving state would work too I guess. Currently it ...
5
votes
2answers
194 views

Shell script (bash) to add or replace the license text contained within .c , .h and makefiles?

I have a set of *.c , *.h and Makefiles in a folder where some files contain the license text and some files don't have any license text. So I need a shell script where I can add license text if the ...
2
votes
1answer
28 views

set flag to remove duplicate records from a file based on some values of the record

I have a file having the following records (pipe delimited): SK200-10|ALBUMIN-SK|INS|SEKURE ALBUMIN 2 X ...
0
votes
1answer
41 views

Restrict user to run shell script except which is defined in sudoer file

I have scientific linux 6.4 running on my system, I have restricted other users to run shell script except one, which is defined in /etc/sudoers file. For example: I have one file.sh in my admin's ...
2
votes
1answer
68 views

After printing the previous line where the file contains a single token now need to traverse through the result to meet the requirement

I have used the below code to print the previous line where the file contains a single token #! /bin/ksh file=input.txt while read line do awk 'NF == 1 { print LAST } { LAST=$0 }' done < "$file" ...
1
vote
2answers
46 views

Using exec in find over ssh from shell script

So, I am attempting to execute the following from within a shell script; ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit" When this runs, it ...
2
votes
1answer
93 views

Bash script for running python virtual environment does not execute

I am trying to wrap the following call into a script, which runs my Python virtual environment: [lucas@lucas-ThinkPad-W520]/home/lucas/bin$ source ...
0
votes
1answer
33 views

BASH paste sourced files into main source

I have a fairly large BASH project, which I split into multiple files to make it more readable. As a result, the main file contains many source statements. Now I'm releasing it on GitHub and I'm ...
1
vote
1answer
51 views

Change a value in a config file, or add the setting if it doesn't exist?

When modifying config files from the command line, I often want to find the setting in the config file and modify that line if that setting exists. If that setting doesn't exist, I want to add it to ...
1
vote
2answers
49 views

how to get string between braces along with string without braces using awk

My input is: ABC_DFG_FRE s(DFR_GHY_JUY) BGR_KIU_PLO s(VFR_KJU_MKJ) output sholud be: ABC_DFG_FRE DFR_GHY_JUY BGR_KIU_PLO VFR_KJU_MKJ
1
vote
1answer
40 views

Create a log file with the same name as input file

I'm new to linux shell scripting. I have few input files that I have to parse one by one. So in my "work in progress" WIP folder I have one input file at a time. While one file is under processing I ...
4
votes
1answer
125 views

how to set environment variables from a shell script? [duplicate]

I'm trying to set environment variable through a shell script. Here is the script with various techniques: #!/bin/sh echo "export SOMEPATH=/root/some" >> /root/.bash_profile echo "export ...
1
vote
1answer
59 views

Fastest way of find and replace in large file with replacing filed present in another file

I have two files. File1 is a csv with 60 fields: 111,Check1|^/h1/h2/h3,22062014184500,20,0..... 111,Check2|^/h43/h40/h9,22062014184500,4,..... 111,Check3|^/h1/h3/h4,22062014184500,0,0,..... File2 ...
0
votes
1answer
53 views

Disable Touchpad automatically at startup

I'm running Mint 17 Mate on a new HP250 laptop. I can turn off the touchpad by typing the following from terminal: synclient TouchpadOff=1 Now I want to disable the touchpad automatically each time ...
2
votes
1answer
24 views

move the search content to different directory

I am on Oracle Solaris. I am using: grep "searchstring" filename.* above command returns my search result. Now I want to move the all the files in above search result (all the files not the ...
2
votes
1answer
68 views

Integer part from float operations without | bc

I read a billion of discussion about this but still have confused thoughts. I just need to use bash to calculate some parameters, and for this operation I need to get the integer part of a float ...
1
vote
1answer
23 views

How do I obtain the kill signal / message / reason within a script?

I am using the following trap: trap OnExit EXIT And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
2
votes
1answer
49 views

Why is the PGID of my child processes not the PID of the parent?

So I keep reading everywhere that this command should terminate all child processes of the parent process: kill -- -$$ Using a negative ID with the kill command references a PGID and from the ...
2
votes
3answers
54 views

Concatenate filename inside of CSV file for each line for multiple CSV files

I have lots of CSV files and I need the filename of each specific CSV file in every line of each file. Original file content of abc123.csv: ColVal_1;ColVal_2;ColVal_3 ColVal_4;ColVal_5;ColVal_6 ...
1
vote
7answers
84 views

Get text between two special characters in a line using shell

I have a line which comes from a file via: cat aaa.txt | grep "HIJK" Output gives: HIJK="My name is HIJK" I need to get the text My name is HIJK into a variable in a shell script. I have tried ...
0
votes
1answer
38 views

How to make xargs ping and head output as expected?

Given an array of domains I would like to obtain their IP addresses, in the following format: 98.139.183.24 98.137.236.24 This script #!/bin/bash domains=(yahoo.com yahoo.ca) printf "%s\0" ...
3
votes
6answers
68 views

Collapse some repeated parts of successive lines

I have data in notepad like this: 4480-1 4480-2 4480-3 4480-15 4581-1 4581-2 4581-3 4581-4 Can we do it using for loop sort of things? With sed? My required output is ...