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

learn more… | top users | synonyms (2)

1
vote
5answers
136 views

How to use grep and cut in script to obtain website URLs from an HTML file

I am trying to use grep and cut to extract URLs from an HTML file. The links look like: <a href="http://examplewebsite.com/"> Other websites have .net, .gov, but I assume I could make the cut ...
1
vote
1answer
21 views

Save and restore terminal tabs with custom tabs title

I have a Terminal window with a dozen named tabs open *(gnome-terminal) I would like to save the current configuration and have it restored with names and directories. Is there a way to do this? I've ...
0
votes
2answers
13 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
1
vote
1answer
25 views

Rename files based on directory names

How can I rename .jpg files in multiple folders based on the name of the folder? I also want the .jpg files to remain in their respective folders and not moved. The folder names have no spaces. So, ...
2
votes
1answer
14 views

Is there an alternative to using rbash to restrict a user on my system?

Basically at the moment I am using rbash to stop a user from leaving his directory on my system. The problem with this is, there is a script in my bin which he needs to be able to run from a script in ...
-2
votes
1answer
36 views

How can I run a script as sudo and for it to not ask me for a password?

I want to run the following script: #!/bin/bash if grep -qs 'MinecraftServer' /media/kiancross/MinecraftServer/MinecraftServer; then echo "Disk already mounted, server boot will continue" else ...
1
vote
1answer
30 views

How can I pass the success (or failiure) of a command to a variable?

I am running rsnapshot to do backups of my NAS. I am forwarding the output of the command (e.g. rsnapshot hourly, rsnapshot daily etc.) to /tmp/rsnapshot_stats_hourly. In another script, I'd like to ...
0
votes
1answer
9 views

How can I pass a function name to a test runner?

I wanted to write my own test runner: do_test () { function_under_test=$1 expected="$2" function_under_test $3 # <-- Line 32 if [ $result -eq $expected ]; then printf '.' else ...
1
vote
3answers
26 views

Loop to check whether a Debian package is installed or not

I like to check whether several packages are installed or not on Debian/Ubuntu Here is my attempt at a script to do this: query=`dpkg-query -W -f '${Status}'` ok="install ok" if ! [ `$query` curl ...
1
vote
1answer
28 views

Sourcing a redistributable script by default

I am creating a bash script which I wish to release on github. The script needs to access the command history but this is not possible without sourcing that script. I don't want users to put it in ...
0
votes
2answers
31 views

Why do I get Illegal number: {1..3}

Why am I getting ./6_sum_square_difference.sh: 11: ./6_sum_square_difference.sh: Illegal number: {1..3} for #!/bin/sh summing () { the_total=0 num_in=$1 for one_num in {1..$num_in} do ...
0
votes
1answer
43 views

Why does this comparison return not equal?

Can't seem to get this to evaluate to true is_equal () { in="$1" if [[ "$in" == "385" ]]; then return 0 else return 1 fi } a= is_equal 385 if [[ "$a" ]]; then echo "equal" else ...
0
votes
0answers
37 views

Increment Numbers in URL?

I want to create a list of URLs. The URLs have two sets of identical numbers which need to be incremented by 1: http://sample.com/poilus/cwrgshs/192/192.html ...
3
votes
2answers
44 views

Why alias inside function does not work?

See the code below: a()(alias x=echo\ hi;type x;alias;x);a I have an alias inside a function, I do not want to change the external environment (that is why I am using () instead of {}), even the ...
2
votes
2answers
57 views

How to return 0 if a pattern is matched from a file? [duplicate]

I have a binary that repacks android kernel (not mkbootimg). I'm making a script to automate the process. I don't want any output on the screen. So I have redirected the output to a file named ...
1
vote
1answer
36 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
46 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
28 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
41 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
29 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
16 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
votes
0answers
32 views

how to reverse the ip address using shell script [duplicate]

In my script, I am getting output as hostname: host1 and IP:100.1.168.192 Now i want to reverse and show the result. Like this i want the result 192.168.1.100 How to reverse it ? My script will ...
1
vote
0answers
20 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
40 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
56 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
1answer
27 views

How to use both && and || operator in shell script [closed]

chkline="Hello world" lastline1=`tail -1 test4.scrn` lastline2=`tail -1 test5.scrn` if [[ ! -f test.scrn && ! -f test2.scrn && ! -f test3.scrn ]] || [ "$lastline1" != "$chkline" ] || [ "$lastline2" ...
2
votes
2answers
40 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
24 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
63 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
47 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
17 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
30 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
58 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
17 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
16 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
48 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
188 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
35 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
35 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
34 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
34 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
41 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
33 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
66 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
95 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
32 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
29 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. ...
2
votes
2answers
477 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
26 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
184 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 ...