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

learn more… | top users | synonyms (2)

3
votes
4answers
111 views

Getting console width using a bash script

I'm encountering an issue where I am trying to get the size of a terminal by using scripts. Normally I would use the command tput cols inside the console, however I want to be able to accomplish this ...
-2
votes
3answers
37 views

How to set own ip address for localhost [on hold]

I have installed centos 7 i want work on Linux,Apache,Mysql,php(LAMP). Can any guide me how to set my own ip config to work
0
votes
0answers
14 views

wget submit webform login to download files on another page

So I'm trying to download some files behind the webform located here https://user.meshare.com/user/login. I looked using firebud and I can see the three variables post, which I post to the site and ...
5
votes
1answer
324 views

A better way than `tee | cut | … | paste`

Trying to do a "lookup" in a pipeline, where the input looks like this: alice 5 bob 7 ... I want to look up codes in the second column in a database and return the corresponding name, and keep ...
0
votes
1answer
28 views

How to execute an installer from a variable? [on hold]

Hi I'm trying to write a script to download and run some installers. The file name is stored in a variable, I use wget to download it, chmod +x the file, and that's as far as I can get. I've tried: ...
0
votes
0answers
23 views

How to pass filepaths in text file as input to another FOR loop?

I am using C Shell. My current working xmlstarlet command: foreach xmlfile ( Test2/ResultReport1.xml Test3/ResultReport2.xml ) xmlstarlet sel -t -m '//RESULT_STEP' -v '@time_stamp' -o '|' -v '@...
1
vote
2answers
36 views

deferring argument in “alias” in .bashrc

I am a dumb user, who works with LINUX (ubuntu 14) My newly purchased laptop forces me to use the bash shell, and it has .bashrc. I used to use the C-shell before that and tried to copy its aliases ...
2
votes
4answers
93 views

awk / sed / etc. concatenating colums in one file

I wonder what is a simpler way to do this: awk 'NR > 1 {print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9$10$11$12$13$14$15$16}' file.in > file.out which is simply speaking " ...
3
votes
2answers
403 views

Command works at the command-line, but won't work in a shell script [duplicate]

I am creating a script and when I try to capture a command return, I have an error of command not found, if I use this command on the terminal: gcloud -q compute snapshots list --format='csv(NAME)' ...
0
votes
1answer
26 views

centos gdrive script, upload to new folder

I'm using https://github.com/prasmussen/gdrive Hello, I'm trying to run a daily script that creates a folder in Google Drive and then uploads a bunch of tar archives in it. So far I can create the ...
-2
votes
1answer
35 views

How to read database name from file in shell script [on hold]

Is it possible to read MySQL database names from a file in a shell script to process multiple queries using the same database name? My Script is .. #!/bin/sh echo "----------------------------------...
1
vote
2answers
33 views

Where can I find shell script for parse JSON on busybox?

I have an IP camera with armv5tejl architecture. There I have busybox. I have to be able to parse JSON responses from curl. The problem is that I don't have programs like: jq, jshon, jsawk... It is ...
1
vote
2answers
50 views

How to test if a file starting with a particular prefix is present in a directory in shell script [on hold]

I need to test if a file starting with "ant" is present in the directory. If that is present, I need to delete that file. The command that I am using now is test -e $FILE_PATH/$FILE_NAME I have ...
2
votes
2answers
27 views

Resize image in a script using Imagemagick

I'd like to create a bash script to resize images up to 800px keeping proportion... My code doesn't work in bash, but it works using identify with a single image : #!/bin/bash for file in ./**/...
1
vote
0answers
34 views

Cron script output not able to log in specified folder [on hold]

I have a Linux script and I want to test whether the implemented script is working or not. I have scheduled a Cron job but I am not getting any output in the log folder. I have tried checking whether ...
1
vote
1answer
45 views

Optimize find -exec {} with multiple conditions : specific files in a dir and specific subdirectories in this dir

My problem is related to music encoding on my NAS and optimisation of linux find command. I have write a script that is totally functionnal but I am sure this not the best way. To summarize: 1/ ...
-3
votes
0answers
25 views

Print lines in one file matching patterns in another file [duplicate]

There are some phone numbers in one file I need to grep information from other file using that numbers among larger set of numbers and their information and result should be placed in separate file ...
2
votes
3answers
189 views

How to check if files are different before copying and overwriting?

I use a little script that copy (using cp) a list of config files to another device. I wonder how to quickly check whether the files were modified since last time before doing it and exhausting the ...
1
vote
2answers
47 views

Use sed to pick out a potentially multi-line log entry

I've been trying to come up with a sed command to pick out a single log entry from our app server logs. The logs are in this format: LOG|2016-07-26_15:37:45:536|entry1|! LOG|2016-07-26_15:37:45:536|...
-1
votes
0answers
23 views

How do I use a file as a command line switch [on hold]

I have a shell script that emails a group of application owners using a command line switch. I would like to change that script to use an editable file as the command line switch. That file would ...
0
votes
2answers
78 views

Split file by pattern

Is there an easy way to split, for example, apache vhost file with multiple vhost into 1 vhost per file? Or something else, allowing to operate only one by one vhost to get grep output . preferred ...
2
votes
3answers
37 views

Specifying redirection options through a variable, in an exec command

I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example : REDIRECT=">>test" ...
1
vote
2answers
47 views

Script to remove files based on threshold value [duplicate]

I have some old file in my Linux server and I need to remove those files which are older than 5 days based on the threshold value. log_space_checker() { Use=$(df -kh /logs | awk 'END{gsub("%",...
5
votes
3answers
260 views

How to check if a glob has an expansion? [duplicate]

Is there a good clean conventional way to do this? For example, if there are any ".gz" files in a certain directory, I want to unzip them. But if there aren't, I don't want to see any error. If I ...
1
vote
0answers
76 views

sudo kill: Operation not permitted over SSH

Using heredoc to execute multi-line commands on a remote machine. Trying to get pid of a server to kill that server located in the remote machine #!/bin/bash HOST_IP="10.180.5.23" read -p "For HOST ...
1
vote
1answer
19 views

Find capacity details and oldest file in Busybox format

I am using Mobax and it has Busybox installed in it. I can successfully get the capacity, available, used and used percentage of the directory and its sub-directories in Linux by typing: clear &&...
2
votes
3answers
44 views

Extract files with specific file extension and keep directory structure?

I have a lot of .CR2 and .ARW files mixed together in a directory structured by date (2016 has the folder 06 and 07 within it with a folder for each day in them. So a file could be located in 2016/06/...
1
vote
4answers
41 views

Create an associative array from the output of two commands

I am trying to create user directories based on an imported passwd file, and am trying to load the data into an associative array: array[username]=directory . I can load the fields into a separate ...
1
vote
1answer
36 views

wrapper script: fork: retry: No child processes

"myapplication" needs some setup or clean up done, so I use the following wrapper script: #!/bin/bash echo "Do important set up stuff" myapplication echo "Clean up" and put it in my path, named "...
3
votes
5answers
196 views

Comparing multiple options in a bash (string)

I'm trying to enable only certain options when using the read command, and to exit the script if a wrong possibility was entered. Tried many possibilities (array, variables, syntax change), but I'm ...
0
votes
0answers
28 views

howto perform a concatenaned command and set result on variable

I need to build a command concatenating other smaller string values: function processES { local status=$KO_UNKNOWN local method="GET" if [ ! -z $1 ]; then method=$1; fi local curl="curl -s -...
0
votes
1answer
27 views

Start Docker container and open web browser on host

I recently faced one non-trivial (for me) case. Maybe you know any way to solve it. I have a shell script that runs Docker command to start the Ubuntu container, which ends up with running guest Bash ...
-1
votes
1answer
62 views

Script to delete all files and keep only latest file

Any advise on how to do delete all files and only keep the latest file in each sub-directories, starting from a specific directory? This is what I have tried: #!/bin/bash find /home/ftp/ -type f | ...
-1
votes
1answer
37 views

Script to monitor a new file

I want the script that to monitor the new file that which comes every day one time to the specific folder in windows Admin proxy and when the file comes we need a mail that should come to us ...
2
votes
1answer
22 views

displaying a date after specific number days by reading a number

i have a file, in which there is a line Password=md@2507 where 2507 is the date when i changed the password for the last time. i want a script that read the date from the Password line of that file ...
3
votes
4answers
65 views

Continuously updating a variable in the background

I'm trying to have a script continuously run a loop that updates a variable in the background, so that the variable is up to date each time it is used. After looking for near an hour, I've come up ...
4
votes
3answers
396 views

Recursively find all files named “file.txt” and execute a sed command

The challenge of my task is that the file.txt can be in subfolder or in sub-sub folders. The general structure looks like this: folder |___subfolder |_____file.txt | |...
1
vote
1answer
30 views

Finding the length of a terminal session

I'm attempting to create my own bash script to output the length of the current terminal session, as well as do various other things with said length. The problem I'm running into, is that in the ...
3
votes
2answers
138 views

executing alias on variable in bash

I am a bash newbie and I came upon this strange behaviour in my bash script. #!/bin/bash V=a alias $V="echo test" echo $(a) #returns 'test' echo $($V) #returns ...'a: ...
3
votes
2answers
59 views

Echo the list of process not running

I have developed a script, the script refers to a file to start the required processes on that server. The script times out after 180 secs. At the end of the script I would like to display the ...
0
votes
1answer
18 views

How to update Mint-Y theme and icons using a script

Situation: Mint-Y is a work in progress and it will continue to change and to improve, with your feedback, after the Linux Mint 18 release. Source: https://www.linuxmint.com/...
0
votes
2answers
41 views

explain recursion syntax

I'm new to shell, and UNIX / GNU/Linux. I'm trying to understand this syntax that is part of a recursion function: [ $i -le 2 ] && echo $i || { f=$(( i - 1)); f=$(factorial $f); f=$(( f * i ...
1
vote
0answers
53 views

Task Automation With .EXE program and Bash Script?

There's a Windows program called Visipics. It finds similar images, not merely duplicates. I find it superior to findimagedupes (I use it with Manjaro and Linux Mint) and competing Windows programs, ...
7
votes
1answer
138 views

How to extract the string between two \n in a file

I have a file with pattern <span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
11
votes
2answers
448 views

Is there a way for shell script to know which program has executed it?

In *nix world, is there a way for shell script to have information about which program has executed it? Example: /path/to/script1 /path/to/script_xyz in this imaginary scenario, script_xyz would ...
0
votes
2answers
33 views

Preform operation in bash only if a variable is less than a second variable

I am building an OS for a virtual machine I made, and while progress has been coming along swimmingly, I have been stuck for a good several hours on what should be a very simple issue: I am designing ...
-3
votes
0answers
35 views

Script (shell or python) to update a web page every 5 minutes [closed]

I'm trying to write a script (shell or python) to update a web page every 5 minutes. I tried this: import time from selenium import webdriver driver = webdriver.Firefox() driver.get('https://www....
0
votes
0answers
42 views

add multiple users to multiple servers [duplicate]

I have a quick bash scripting question. I'm trying to add multiple new user accounts to multiple RedHat servers in my environment. This the script I've come up with so far, but it's not quite ...
0
votes
2answers
38 views

if last 4 file size of a directory are same with each other then exit otheriwse continue [closed]

Please give me any shell bash script that will help me doing following task: if last added 4 file size of a directory are same with each other then exit other wise continue Example : ls -l $...
1
vote
2answers
148 views

#!/bin/bash exponent

I'm having trouble running exponent operator in a shell script #!/bin/bash clear number1=8 number2=2 sum1=$(( number1 ** number2 )) echo "8 ^ 2 =" $sum1 it returns expecting primary: " number1 *...