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

learn more… | top users | synonyms (2)

1
vote
1answer
23 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
30 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
3
votes
2answers
132 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...
3
votes
2answers
105 views

Can we find page count of a file in Unix/Linux?

I want to count number of pages in the file /var/log/messages, so that I can use pr command to start printing from the page I want to. For example, suppose that /var/log/messages file contains 300 ...
1
vote
0answers
12 views

FFMPEG stream won't show up on Justin.tv

INRES="1366x768" # input resolution OUTRES="1366x768" # Output resolution FPS="35" ...
2
votes
1answer
31 views

Controlling bash script concurrency, flock inheritance

I have a bash deployment script that handles deploying updated code to a Tomcat instance on CentOS, however, both Chef and RunDeck may invoke the script, and since Chef runs periodically there is a ...
2
votes
2answers
33 views

Merging files by rows

Is it possible to copy the whole rows of File1 in a new File3 following the instruction given by File2 by using a simple bash script using sed or awk? File1: /*two or more columns*/ AC 456324 DC ...
2
votes
1answer
65 views

merge csv files by first column

I have 3 csv files like this. csv 1: 1,aaaa,bbb,2014-04-01 2,qwe,rty,2014-04-03 3,zxc,cvb,2014-04-05 csv 2: 2,j,k,2014-04-01 3,a,s,2014-04-04 5,g,h,2014-04-08 csv 3: 2,a,s,d,f,g,2014-04-01 ...
2
votes
1answer
28 views

setenv not working in tcsh

I am trying to install a program on my brand-new CentOs. The installation requires setenv, which apparently does not work, not even in the tcsh shell. Can anyone give me some advice? [Anna@anna ...
1
vote
1answer
47 views

bash: syntax error near unexpected token `('

I am trying to concatenate some files side by side. I use the pr command in the terminal. It works well, but when I use it in a shell script, I get the following error message: syntax error near ...
1
vote
0answers
40 views

Sourcing nested sourced bash script multiple times causes an infinite loop [closed]

I have a cronjob that sources a configuration file, so as to put some variables in the environment, and then runs a script. This config script sources another more general config file that sources ...
3
votes
1answer
16 views

How to execute as the logged-in user in a sudo script (OSX)?

Is there a way to switch contexts like that? The script in my specific case is an installer postinstall script, which requires sudo privileges only for some of the tasks and requires the logged-in ...
0
votes
0answers
41 views

Copy all files except those that are executable [migrated]

I have a backup script that copies all the files in my programming directory to an external HDD. Right now, the output files are called program.out and my script is set to ignore them, but I would ...
0
votes
1answer
42 views

Converting windows date logic into Unix [closed]

I had coded the below logic in Windows batch scripting and I need to replicate the same in Unix. # Calculating Yesterday's Date for /F "tokens=1-4 delims=/- " %%a in ('date/T') do set DY=%%c for ...
1
vote
2answers
65 views

SCP Automation in production environment [duplicate]

I want to implement the use of scp command in a production environment. I don't want to provide my password in the automation script. Is there any way? I need step by step solution.
1
vote
3answers
51 views

what does the -z flag mean here

What does the -z flag mean in the code below: if [ -z $TEST_PARAM ]; then And is there a list of such flags? For a flag like ls -l, I know where to find it, but for a single flag, I didn't get any ...
4
votes
4answers
268 views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
2
votes
1answer
32 views

Using xargs with git

I am trying to practice using xargs. I tried the following, passing the SHA1 via xargs: $ git show SHA1 --name-only I also tried: $ git log --author=jim --grep="patch" |head -n 1|cut -d ' ' ...
5
votes
1answer
154 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
115 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
52 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
57 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
186 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
241 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
64 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
65 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
42 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
57 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
54 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
30 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
90 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
44 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
49 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
50 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
197 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
30 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
42 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 ...