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

learn more… | top users | synonyms (2)

1
vote
1answer
66 views

Test for open TCP port in bash script

I want to delay the script execution until a certain server process is ready, which it is once it accepts incoming TCP connections. How do I test if a local TCP port is open (I get a SYN/ACK answer)? ...
1
vote
1answer
21 views

Store delayed shell output to variable?

I have a script which stores output of a command inside a variable like this: my_var=$(command) However, some of the output is not being stored in the variable, I am assuming because it is ...
1
vote
1answer
80 views

awk with variables in condition and in output redirection file

I would please like some help with this command because I didn't find anything in documentation that can cover everything I want. I have some variables that are global, so I would prefer to keep them ...
1
vote
3answers
65 views

Shell Scripting: Comparing something to nothing?

I have this script to check for internet connectivity. I use ping for it. Whenever I use ping google.com -c 4 | grep time it produces a non-empty response. Something like 64 bytes from ...
1
vote
2answers
50 views

How to copy only files in a specified directory to another folder

I'm trying to copy only the files from one directory (not including folders or any files in its subfolders) to another location using cp /media/d/folder1/* /home/userA/folder2/. It is copying the ...
1
vote
1answer
333 views

How to launch shell script with double click in CentOS 7

I need to be able to execute an executable shell script (sh) with a double click. I set the executable flag on the permissions for the file, and yet when I double click on it, it opens in a text ...
1
vote
1answer
39 views

Replace a string in a text file using a shell script not working properly

I have a text file containing this: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1 and I want to replace the 1.0 to 2.0 so that it becomes: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1 so I use this ...
1
vote
1answer
77 views

Processing output from an sqlite db into a ksh array with spaces

I am querying an SQLite3 database like so: input=$(-separator "," "SELECT field1,field2,field3 FROM table1") and get this result: Red,Yellow is a color,Blue I need to insert this into an array, ...
1
vote
1answer
33 views

Files missing after using mv and parameter substitution in a loop

Related questions to missing files after mv don't appear to answer my question. The following commands were run within the working directory where the files are located, resulting in missing files. ...
1
vote
3answers
167 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
1
vote
1answer
191 views

Print lines between two patterns matching a condition in awk

How can I print lines between two patterns which meet a certain condition? For instance for an input file partially containing the following: Time %MEM %CPU %SWAP 00:05:02 7.3 ...
1
vote
1answer
170 views

Shell script to change directory of terminal and open a second terminal

I am new to writing shell scripts and I am trying to write a script to CD to a folder where my programs are saved for one of my classes, then have a second terminal open that ssh's to a server used ...
1
vote
3answers
80 views

How do you parse through a subdirectory where the path contains spaces? [duplicate]

I'm trying to parse through a set of files in a directory on a mapped drive. However, I can't seem to resolve an issue that seems to be because of spaces in the path to the subdirectory. Would ...
1
vote
2answers
147 views

How to format decimal number to display the preciding zero but not the trailing ones?

I have the following script on Ubuntu 14.04.1 LTS 64-bit bash command prompt: S=0.030 F=0.150 N=10 reso=20 DIFF=`echo "scale=3; $F - $S" | bc -l` df=`echo "scale=3; $DIFF / $N" | bc -l` is=`echo ...
1
vote
1answer
307 views

nvm command not available in bash script

I am trying to build a script in in which nvm and eventually node will get installed. I have installed nvm with cURL. I see the modifications in the .profile or .bashrc file (both work) and when ...
1
vote
1answer
72 views

How to use bash shell for gnuplot to show Greek letter?

I want to write a bash shell for gnuplot to produce figures automatically. But my figure includes Greek letters inside. I have known their ASCII number, how can I show them correctly in figures after ...
1
vote
2answers
100 views

Creating a shebang pointing portably to an interpreter in the folder of a script

I have a JS file (file.js) that I want to have executed as a command line shell script through nodejs (iojs actually); I'm using MINGW Git Bash on Windows. The standard way to do it is to put the ...
1
vote
2answers
56 views

add a new line to a delimited file

So I have a file name test.txt inside that file I have about 20 lines of text that are delimited by pipe | Example: John|freshman|seatle|math|4|fulltime Bob|senior|Tacoma|biology|4|part-time I ...
1
vote
2answers
88 views

Copy the first 2 lines from a file and then remove the lines

I need to process a file using a shell script. The file arrives with the data as well as some embedded information releavant to how it is processed. The file is in the following format; ...
1
vote
1answer
63 views

using script function rather than keyboard input

I'm writing a shell script to change a user's password. I tried to use the passwd command, but that command always asks for the old and new passwords to be typed; it won't accept them from my script. ...
1
vote
2answers
44 views

remove lines from an output file from diff

I have a script that uses diff -c then puts the output on a text file. What I want is to remove the line that does not have the "!" and display the lines with the exclamation mark. Is this possible? ...
1
vote
2answers
275 views

Get files from SFTP server and manipulate in memory

Is there a BASH way that is able to access a SFTP server, "access" a file and without downloading it read it in a buffer, manipulate the content and then store it locally. I know this can be done ...
1
vote
2answers
247 views

Compressing multiple files in different folders without folder structure

Currently I create a copy of my log files like this: # tar -cvzf /var/www/vhosts/example.com/httpdocs/myfiles.tar.gz /var/www/vhosts/example.com/logs/access_log ...
1
vote
1answer
44 views

How does executing a file change the std input?

Imagine I have a script, which contains the goto command. The goto command will search in the std input for a line like this : jumpHere. But the std input is by default the terminal. It only makes ...
1
vote
1answer
31 views

How to use passed-in parameters for shell script?

I know little about shell script but I want to try to implement some complicated scripts. Say I have a doitall.sh with the content like: zip -j version_a_en.zip en_filea1.txt en_fileb2.json And a ...
1
vote
1answer
78 views

How to check the file type in a script

I want to do a loop for all the images in a directory. The images doesn't have extension so I have to read the first bytes of the image to know its type. The loop should end up being something like. ...
1
vote
1answer
118 views

Number of packets sent and received on an interface

I'm interested in creating a script which prints total number of received packets and sent packets on an interface. The output should be like: interface TX: number RX: number Can anyone help me ...
1
vote
3answers
74 views

Splitting a string up to a specific location

I have a question and wondering how to address it with sed? How does one cut a variable up to a specific location, in my case _g? Example variable="This_is_good_g0r0s0_continues" I need to cut ...
1
vote
1answer
93 views

get only file name while iterating over directory instead of path with it [duplicate]

$ script.sh -i /storage/testFile -i stores the path of /storage/testFile/. I want to iterate over file in testFile. Everything goes good, but I want to make this code cleaner and add a directory ...
1
vote
4answers
480 views

How to delete the files in one folder which are more than 60 days old in UNIX?

I know how to delete the files which are more than 60 days old by modification time, but I want to delete files based on a timestamp in the file name. For example, I have the below files for each day ...
1
vote
1answer
70 views

'hhighlighter' wrapper script saying command not found

I have gotten the wrapper script 'hhighlighter' from https://github.com/paoloantinori/hhighlighter which colors anything you want in stdout. I followed the instructions about installing ack-grep, ...
1
vote
2answers
343 views

Why double ampersand chained conditions runs in background together the last one?

I have some conditions for some background job to run: condition-command && condition-command && background-job & The problem is: I want the conditions to block until the job ...
1
vote
3answers
242 views

Generate networking configuration files using sed and bash

I am a bit rusty on my scripting abilities and am trying to find a good starting point for creating a script that creates files (generating new file names) and edits the IP address in the file by ...
1
vote
1answer
479 views

Rename bash script - false no such file or directory error

I am trying to rename a few hundred files based on another file in the same directory. I found a script and with modification I have the following: while read file; do echo mv ...
1
vote
3answers
199 views

for loop for running a command for all files in a folder

Suppose I have a folder which contains a lot of audio files. How can I write a for loop so that for each file audioname.mp3 in the folder, these commads are run: convert -size 300x200 xc:lightblue ...
1
vote
1answer
38 views

Comparing value in same column and directing output to new column

I have my input file as DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11 110005 DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11 110006 DPortal=ECCN ...
1
vote
2answers
74 views

Randomize arguments ( that hold color codes) from an array

I have the array (shown below) with arguments that hold color codes. The intended purpose of my script is to randomize those arguments when the user inputs "scriptname randoms Text" so that every time ...
1
vote
1answer
40 views

Search and remove with regular expression

How do you use regular expression in bash to search any given string and remove occurrence of particular word? This is the expression I've come up with ^([A-Za-z-]+)(-).*(el6.*)$ What I would like ...
1
vote
1answer
81 views

C Shell detemined the file

I'm very new to C Shell. I'm trying to read a file from the command line, and determine whether it's a zip file, a .txt, a symbolic link, a pipe, or whatever ("unknown"). Then I'd like to execute a ...
1
vote
1answer
68 views

For loop for curling on multiple pages with API's

I am trying to crawl a website for fetching pages using an API. When I issue the command cd desktop/mysite ; curl -O https://api.mysite.com/info?page=2 I get the data on the desktop. Then I wanted ...
1
vote
4answers
112 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
1
vote
1answer
162 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
1
vote
1answer
648 views

Start a background process from a script and manage it when the script ends

I'd like to run and configure a process similarly to a daemon from a script. My shell is zsh emulated under Cygwin and the daemon is SFK, a basic FTP server. For what matters here, the script ...
1
vote
2answers
513 views

find a specific string pattern from a file in Unix Shell Scripting

I have the below command. unzip -p GLP.K4C.S06F5.BG57218-rdf.zip | grep ":taxonomies-" | head -1 which gives me the output as, <j.2:Taxo_Version ...
1
vote
3answers
184 views

How to sum match numbers

I'm new at scripting, and need some help. Will appreciate your answers. I got this assignment, which is to find the sum of all five-digit numbers (in the range 10000 - 99999) containing exactly two ...
1
vote
1answer
167 views

Running commands after ampersand symbol & in a remote ssh session

I have a shell script that initiates a long, resource-intensive command on several different machines. In order to execute the script on each machine in parallel, I have an ampersand symbol after ...
1
vote
2answers
132 views

Expect script: How to handle two processes?

I am using Expect to automate VoIP calls for quality measurements. My script is calling another VoIP client for a given amount of times. Before the calls should be handled, tcpdump should sniff all ...
1
vote
2answers
753 views

Motion start sequence - shell script modification

I've tried to modify this script to start Motion using the following libraries. I start the script by entering the following command into terminal: sudo /etc/init.d/motion start Which Gives: ...
1
vote
1answer
120 views

linux pgrep by excluding specific user

I'm using pgrep command on a shell script to monitor some java application. But there is a continues service from java which is giving problem on my code. That process belongs to another user. So, is ...
1
vote
1answer
114 views

How to send a mail when someone remote connects to my server

I would like my server to send a mail to me when someone connects remotely over ssh to my server. who only gives me back the Username, TerminalID and Date. I cannot use only that, I need to check ...