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

learn more… | top users | synonyms (2)

1
vote
1answer
43 views

How can I use regex to extract the text following two conditions into a variable?

I'd like to extract a setting for a given host in the ssh_config file and put it into a variable. Host mysite HostName 123.1.1.1 User myuser Port 13245 GSSAPIAuthentication no ...
0
votes
4answers
61 views

bash script, list all the files over a specific size

so I have a line of code like this: result=`find . -type f -size -1000c -print0 | xargs -0 ls -Sh | head` for i in $result; do item=`wc -c $i` echo $item1 done this will print out all the ...
1
vote
1answer
58 views

script to parse integer and convert it to char code

I am noob on Unix. I've a very unique problem where and really appreciate your help. I need to parse string containing hash code value and convert the hash code is equivalent char representation. Here ...
0
votes
1answer
160 views

Bash script, ask for user input, to change a directory, sub directorys, and file's mtime atime linux recursively

Using GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) I am a bash scripting novice, not sure where to begin except at shebang #!. The following command. touch -a -m -t 201501010000.00 ...
0
votes
2answers
37 views

How do I download a PDF, then output a chunk of text?

My city water bill is emailed to me every month as a link to the current PDF hosted on their server. So I can easily download this PDF any time I want. How do I take that PDF and extract my account ...
0
votes
0answers
26 views

Mount /var at boot runlevel 2 - problems

I'm working with a system that (for various reasons) often gets corruption on the /var partition. To this end I'm hoping to run e2fsck on it during the regular boot. I've commented out the /var ...
1
vote
1answer
80 views

Connecting 3 OpenVPN connections through a shell script

For work I need to connect to 3 different OpenVPN connections every day. I'm using a shell script to speed this up, but I feel like it could be done better. Currently my script is: #!/bin/bash cd ...
0
votes
2answers
50 views

Bash variable substitution problem

I have a problem with variable substitution in bash. I'm doing like as explained in below code, but cd $d is not going into original directory i.e. after expanding $var export var="/a/b/c" for d ...
0
votes
1answer
109 views

Run a command under sudo over SSH

I am accessing remote machine in Linux using Bash scripting.My code is as follows #!/bin/bash ssh -i manu_bp.pem ubuntu@54.68.67.68 <<EOF sudo -s cat ...
2
votes
2answers
70 views

How can I invoke a prompt for an ssh key passphrase during the execution of a script?

In my ssh_config file there are multiple entries for sites on the same server such as: Host site1 HostName 123.1.1.1 User myuser Port 13245 GSSAPIAuthentication no ...
-2
votes
2answers
28 views

How to use shift to shift $@ one over

I am running a shells script with 3 arguments. I am getting the word count of each one. But I want to skip over the very first argument, maybe by using shift or something else. Most of the examples ...
1
vote
1answer
110 views

Searching file based on data range

I previously posted requesting help with counting occurrences of a string. I'm now hoping to search for the occurrence of a string within a range of values and print out a similarly formatted file ...
2
votes
2answers
63 views

How to append word count of file to file without adding the total

I am running a bash script where I am appending the line count of the arguments, which are files, to another file. It does it correctly, but I keep getting a line that says "total X", X being the sum ...
1
vote
1answer
98 views

Compare two Arrays in KSH and output the difference

I am not extremely familiar with KSH (Actually just started using it) and I am having problems with trying to create a script that will essentially compare two arrays that have been stored and then ...
0
votes
1answer
33 views

How to make $@ start one iteration ahead

I'm running a bash script and am reading file contents of each one, but I want to skip the first one. I know of the "shift" command, but I'm having trouble getting it to go one over. I currently have ...
1
vote
2answers
109 views

Multiple File Redirection with awk and find

I have some files in a directory. And I want to add some lines at top and end of file using awk. Example: My awk command: awk 'BEGIN { print "line1\nline2" } { print $0 } END { print "line3\nline4" ...
1
vote
2answers
49 views

Quoting / escaping / expansion issue in “command in a variable”

I want to run a command such as this in a bash script: freebcp <authentication and other parameters> -t "," -r "\r\n" When run directly on the command line, the command works as expected. But ...
0
votes
0answers
34 views

error with Transcoding with ffmpeg activated by inotify

I’m trying to automatically transcode videos, that are begin uploaded constantly to a server. That is why I have came up with the idea of using inotify, by checking every moment for new files on the ...
2
votes
1answer
59 views

Linux lockfile starvation

I want to use lockfile functionality for a bash script that will run in parallel. The problem is that in a functionality as in the script below, a starvation can happen in case that the first one to ...
2
votes
1answer
230 views

How to get binary representations of strings in Shell?

I'm using openssl dgst -sha1 -binary to get hash values of my strings in binary format. (I'm using -binary flag because my version of openssl adds "stdout" before each hash value on default output, ...
0
votes
1answer
64 views

make custom commands on android 4.4.2

I want to program and debug in my android phone. To do that I downloaded c4droid and it's gcc plugin. after a lot of tries I understood that gcc is in directory ...
0
votes
1answer
39 views

Understanding a signal script

I have the following trap script but the idea about it, is little vague to me. #!/bin/bash for i in {1..64}; do trap "echo 'signal[$$] Caught signal SIG$(kill -l "$i")($i)'" "$i"; done; read -s ...
0
votes
1answer
44 views

sh test two conditions gets [: missing `]' [closed]

I have an error that is hard to clear. All that is supposed to happen is to test two conditions and then do something. The goal is to is it is empty or if it's a match. if [ -z "$_BRANCH" ] || [[ ...
0
votes
2answers
40 views

Why my script execute in / instead of /mydir?

This is my script,it simply update a localrepo of slackware when notify a change on fs. It work in background,but has a little problem instead of working in /userdir where are present .gpg,it works ...
1
vote
1answer
68 views

Using cURL, How can I fetch a numerical string which contains commas and spaces and convert such to a NON COMAFIED string [duplicate]

Example: Google's Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API using the below script. The issue is; that numbers WITH commas or spaces are ...
0
votes
0answers
133 views

Establish communication between Arduino Mega & Linux Terminal in Ubuntu 14.10

I am failing regularly in establishing syncing between my arduino mega(/dev/ttyACM0) and the terminal. Even I thought of establishing output using GNU Screen utility. The terminal just hangs for ...
4
votes
2answers
94 views

status check for sleep command

I have run sleep command in background as follow , How can I know the status of execution ..? Command sleep 2d ; find /home/disk1/ -exec touch {} \; & How can I know that its executed for 1 ...
5
votes
2answers
144 views

Create symlink tree in existing directories

I carry all of my music around on a 1TB USB drive and have a udev rule to symlink it to $HOME/Music/ when I plug it in to one of my laptops, which it does. The issue I have is that this works fine ...
1
vote
2answers
38 views

Help with Script to Process txt file to CSV

I am trying/attempting to write a script to turn this: Mikrotik01#show unique routing entry | 192.168.255.232 | inc ID Thu June 10 15:21:32.808 CST Unique Entry: 192.168.255.21 Unique Entry: ...
1
vote
1answer
46 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. ...
3
votes
2answers
534 views

How to ls without recursive

I am trying to ls some files with a pattern in a directory. I only want to scan the first level not recursive. My script: for i in $(ls $INCOMINGDIR/*$BUSSINESSDATE*) do echo $i; done Above ...
1
vote
3answers
36 views

UNC Argument in bash scipt

I want to create a bash script with a "pure" UNC (i.e. I do not want to escape the backslashes literally) as an argument, i.e. something like: ./foo \\my\share\is\here However, as is natural, the ...
2
votes
1answer
353 views

bashscript to detect right arrow key being pressed

Why does this always detect as true, even if the keycode is not right-arrow-key? stty_state=`stty -g` stty raw; stty -echo keycode=`dd bs=1 count=1 2>/dev/null` stty "$stty_state" echo $keycode ...
0
votes
1answer
111 views

Using the cURL command, how does one fetch stock data which comes back *without* commas and spaces?

What can I add to the below script so that it fetches the stock data and brings it back WITHOUT any commas and spaces? For example GOOG Outstanding shares is 675,000,000. I desire the output of ...
1
vote
1answer
105 views

running script at specific times without using cron [duplicate]

I'm trying to run a shell script in (#!/bin/sh in HP-UX) on exact times(hh:mm:ss) hh:05:00 .. hh:10:00 .. hh:15:00 .. hh:20:00 .. hh:25:00 and so on. I understand this could be done using cron but I'm ...
1
vote
1answer
68 views

Using cURL command-line tool on Mac, how does one fetch stock data which comes back *without* commas? [duplicate]

The below script is not working. cd desktop/quoteUpdate while true do curl-o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=sl1" sed -i '.bak' 's/,/ /g' quotes.txt ...
5
votes
2answers
178 views

Two-words argument in shell script

I have a problem with a shell script. It is supposed to read arguments: index, date, time1 (the beginning of the interval), time2 (the end of the interval). It should count how many times the ...
-1
votes
2answers
57 views

Shell script issue when added to cron

I have written a shell script in order to monitor Nagios service status continuously (See this question), which is as follows: #!/bin/bash RCPT="abc@xyz.com" service nagios status | grep [0-9] if ...
1
vote
1answer
69 views

script needs to add another loop

script which runs netstat -tulpun | grep -i port_from_the_list & takes the output for running the next command I need to run 2 command on all the server mentioned in the list. server: Jan port: ...
0
votes
0answers
21 views

Pcmanfm keeps deleting and recreating my thumbnails

I wrote a little shell script to handle cbz/cbr thumbnails in Pcmanfm instead of using Evince and every GNOME thing coming with it. The thumbnails are created and can be used normally BUT they seem to ...
0
votes
2answers
46 views

Fetching data from server by FTP command

"Fetching data from server by FTP command" is not a problem .But if I like to fetch the today's file from the server, whose name is like (BACKUP20141210) and if it presents in a folder with previous ...
3
votes
5answers
326 views

Awk - output the second line of a number of .dat files to one file

I have searched through previously asked questions and can't find an answer to what I am trying to do. note, I am new to linux. I have multiple files something like: (in reality i have 80) file1.dat ...
0
votes
5answers
73 views

Getting the shellscript to display a chosen file extension

I'm new to this with shellscript and Linux and now I'm stuck. I shall write a simple program that allows me to search for andy file extension I want and then display how many of them there are. I've ...
1
vote
1answer
43 views

Computing differences of column entries

I have a textfile with: 1 100 2 80 3 70 4 64 Now I need another file that contains the first column equal to above and the second column should be the difference of to consecutive values of the ...
1
vote
2answers
26 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
3answers
134 views

How do I make an output for grep fail?

I am using if-else statement to search for keywords and displaying the results in the terminal, here's an example of my code. read finding if ["$finding" != "" ]; then grep $finding ...
-1
votes
2answers
42 views

Script which takes details from file & runs command

It would be helpful to understand how can I connect the second column in the script. currently using the below for loop for i in cat server do echo ===$i==== ssh -q $i 'netstat -tulpun ...
1
vote
1answer
55 views

How do I display the whole line of text?

Example of my information: Fruit,Quantity:Cost,Sold Red Apple,10,1,5 Green Apple,10,2,20 Orange,20,1,10 Here's my code: if [ "$fruit != $blank" ] && [ "$quantity" == "$blank" ]; then ...
1
vote
2answers
413 views

Can I put more than 1 condition in if?

Is it possible to put more than 1 condition in an if statement? if [ "$name" != "$blank" && "$age" == "$blank" ]; then Is it possible? If not how am I supposed to do that?
-2
votes
1answer
26 views

'Is a directory' while trying to pass to destination directory

I've been trying to get my script to work from a cron job so that I can automate a backup of my /home directory, but unfortunately when I run with run-parts to test if the script will work I keep ...