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

learn more… | top users | synonyms (2)

0
votes
1answer
16 views

Unix: Problem with cmp command

Let me give you an idea of what I am doing. I am running a script that is doing basic OS processes for two systems Linux and SunOS. Well the first directory it runs is called sol0. The script puts ...
0
votes
1answer
9 views

v4l2-ctl error in script

I can use v4l2-ctl in command line like these: v4l2-ctl -d /dev/video1 -c focus_auto=0 v4l2-ctl -d /dev/video1 -c exposure_auto=0 But it has error when I run them as a script in a file. for example ...
0
votes
2answers
39 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
votes
6answers
52 views

Find all numbers not in a range

I have a file with following content :- 2 4 5 and have range, say 1 to 5 . I need a shell script whose output will be 1,3. That is the numbers which are not present in the file and within the ...
2
votes
1answer
21 views

Intercept and modify commands in bash scripts

I have some scripts and some commands in the scripts are like this ./executable arg1 arg2 .. argn I want to change the above command to LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 ...
3
votes
2answers
39 views

Execute command after inotifywait established watches

Inside shell script (test.sh) I have inotifywait monitoring recursively some direcotry - "somedir": #!/bin/sh inotifywait -r -m -e close_write "somedir" | while read f; do echo "$f hi"; done When I ...
0
votes
1answer
34 views

Crontabbed shell script not able to create/write to a file

I have written a simple shell script to backup the tables in my DB using the mysqldump command. The command simply dumps the DB into a dbName.sql file. However, if the dbName.sql file doesn't already ...
1
vote
2answers
37 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
votes
0answers
22 views

helping get a shell script right from github

I came across this script on github. https://github.com/loganbraga/dotfiles/blob/master/bin/runOrRaise #!/bin/bash if [ $(pgrep $1 | wc -w) -gt 0 ]; then if [ $1 == "iceweasel" ]; then wmctrl ...
1
vote
0answers
26 views

Questions about whiptail and bash functions

I'm a bash newbie. Say I have this script #!/bin/bash function cpp-lang { yum install "Development Tools" } function updatesys { yum -y update yum -y upgrade } whiptail ...
4
votes
4answers
519 views

How create a temporary file in shell script?

While running a script, I want to create a temporary file in /tmp directory. After execution of that script, that will be cleaned by that script. How to do that in shell script?
0
votes
1answer
22 views

Setting up a script on an AMI box to create directories - vsftpd, pam, mysql

I'd like to first say I'm a noob when it comes to linux, so please excuse my confusion. I'm trying to setup vsftpd on a amazon ami 64 bit box, free tier micro. Following these instructions, ...
2
votes
2answers
243 views

How do I use a function return as a condition of an if else then shortcut?

There are instances where a function needs to execute and return to the caller and this works for me. if tst; then echo "success" else echo "failure" fi function tst () { return 0; } ...
1
vote
1answer
36 views

split line based on space and delete the second part

I have a big file >fid|29290408|locus|VBIEntCas2262_0001| Phosphoglycolate phosphatase (EC 3.1.3.18) [Enterococcus casseliflavus EC20] ...
1
vote
2answers
50 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; ...
0
votes
1answer
25 views

Error while running script with nohup

I got this error while running my script with nohup sh: syntax error near unexpected token `(' My script is as follow: #!/bin/bash report_log="report.log"; grep -A 3 'successful\|ERROR COUNT ...
-1
votes
1answer
24 views

multiple input in a awk file

Please guide me to get out of it. Thanks in advance. I am having a situation that I have to write a awk script which takes the input of two .out files and generate a single .txt file. $ cat ...
2
votes
1answer
44 views

How do I securely download files in shell scripting?

I am writing some shell scripts to automatically download software packages off my server and set them up on customer servers. At some point within the script, the download command is wget ...
-5
votes
2answers
34 views

placing things in a users home directory with .deb

i am making a .deb installer and would like to place some files in the users home directory but i can not hard code a username. does any one know of any other places in the file system that i could ...
0
votes
1answer
36 views

finding and replacing text [duplicate]

Does any one know how to find and replace text in a file. it can be implimented into a bash file. i would like to find the line and the output the text to it the file can only be opened with the root ...
0
votes
1answer
25 views

How to automat password entry without user interference?

How to type password automatically without user interference. For example echo 'MyPassword@2014' > su UserName I want to automat this in my script. The script should not wait for input. It ...
3
votes
3answers
70 views

The output I get via “echo” works as a command when pasted to terminal, but not in the script

I'm trying to change the files generated by an app that unfortunately often contain spaces. I have managed to get "echo" to give me output that works if copy pasted into terminal, but when I try to do ...
0
votes
1answer
20 views

Bash script: array elements containing space character [duplicate]

I'm getting started with bash scripting. I'm working with array elements that contain space characters. In the code below, the third array element is "Accessory Engine". I tried to set the space ...
1
vote
1answer
75 views

Why does the printf statement in this loop output the array out of sequence?

When I execute the following code, the output of the printf statement appears to show array out of sequence. In the declare statement the Source item is declared before Destination and in the output ...
0
votes
1answer
20 views

How to assign the cat output of a bash script to a variable in another script

I have a bash script that produces a cat output when it takes an argument. I also have another bash script that executes the first bash script with an an argument that I want to produce cat outputs ...
-4
votes
2answers
36 views

how to find a file extension with multiple dots [duplicate]

I'd like to extract the extension out of a filename with multiple dots. For instance: gbamidi-v1.0.tar.gz I should get "tar.gz", not "gz" or "0.tar.gz". I prefer a solution not relying on bash ...
1
vote
5answers
330 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
30 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
22 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
46 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
17 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
39 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
34 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
29 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 ...
0
votes
1answer
29 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
45 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
43 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
47 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
61 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
40 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
49 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
32 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
51 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
30 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
24 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
41 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 ...