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

learn more… | top users | synonyms (2)

1
vote
0answers
3 views

i3status script that change its text by itself

I am trying to add a block for rss the latest news in my status bar. The news is composed by a title and a description. The full text doesn't fit in the status bar, so I would like to make it read ...
-3
votes
0answers
15 views

Removing intermediate line breaks in muliple columns except the last new line character [on hold]

Suppose If I have the data like this Col1|Col2|Col3 <br\> 123|abc\n<br\> xyz\n<br\> |abc\n<br\> def\n<br\> other rows<br\> <br\> In the above newline ...
0
votes
2answers
31 views

tr -d not work with carriage return

I want to get rid of \n from variable I found many answers for that which say "use tr -d" but tr -d not work for me echo "$test" | od -c 0000000 4 4 2 5 2 \n 0000006 then I use tr -d ...
1
vote
3answers
46 views

if always false with equal variables

I first get file size info with curl fileSize=$( curl http://linux.die.net/include/sys/ioctl.h --head | grep Content-Length | awk '{print $2}') echo $fileSize is 1825 then I download the file and ...
0
votes
2answers
23 views

Why is crontab giving me a permission error message when I copy my backup?

I use a PuTTY session to copy my nightly backups to another location. I log in as the root user and change directories to /store/BackupLocation which holds backups from the last 100 days. I can then ...
0
votes
1answer
34 views

Kill a running shell script, and kill all process running within it

I have a shell script running in the background, which runs 5 different jobs. When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will ...
0
votes
4answers
36 views

Catching the last returned value in Unix

please help me with this. I am doing a grep test file.txt and I want to catch the whole value and print it.I am doing this, grep test file.txt if [ "$?" -eq 0] then echo success else echo fail fi ...
0
votes
1answer
20 views

Execute a function before specific programs

This began with the want of adding SSH keys to ssh-agend on demand, but because this isn't possible with OpenSSH, I came up with this zsh script instead. But for a reason I can't figure out, instead ...
4
votes
2answers
64 views

Search directories for multi line string

Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines. So I know ...
1
vote
3answers
40 views

Bash script for service to check mount before start

I need to insert on some service scripts a condition on the top to check whether a device is mounted or not. I'm not very familiar with bash script... This is a first try I wrote but it doesn't ...
2
votes
3answers
182 views

awk : parse and write to another file

I have records in XML file like below. I need to search for <keyword>SEARCH</keyword> and if present then I need to take the entire record and write to another file.(starting from ...
0
votes
2answers
85 views

For loop cannot distinguish * syntax

set -x for f in ~/1/2/*/*_1.txt; do subdir="${f%/*}" pushd "$subdir" &>/dev/null file="${f##*/}" expTool INPUT1= "${f##*/}" INPUT2= "${f%_1.txt}_2.txt OUTPUT1= "${f%_1.txt}_3.txt" OUTPUT2= ...
3
votes
3answers
315 views

How to sleep until a given date & time?

I want to write a shell where given a date (day-hour-min) e.g. 10:00 AM Sun 2:30 PM Mon ... It sleeps until that exact date & time. I thought one way of doing it is, I could get the current ...
1
vote
1answer
34 views

timeout doesn't work with accumulo shell in bash script

I'm trying to check if a scan of an Accumulo table times out (to see if the table is corrupted). #!/bin/bash timeout -s KILL 20s accumulo shell -zi myInstance -u root -p secret -e "scan -np -t ...
-2
votes
0answers
23 views

Restarter script error in archlinux

I was running a autorestarter for some traffic exchange when this error occured to my VPSs " blah blah blah [26678:26678:0203/150900:ERROR:process_singleton_posix.cc(268)] Failed to create ...
0
votes
0answers
41 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
0
votes
0answers
23 views

Nginx Performance Monitoring: How to collect CPU, Memory and Disk Utilization data?

I'm relatively new to shell programming and I need to collect statistical data on nginx web server performance running on Linux VMs for further analysis. I have checked some tools and I find dstat ...
1
vote
1answer
24 views

Cron Job Hourly Except Certain Time Frame on Friday

I want my cron job to run every hour, every day except Friday when I don't want it to run at all between the hours of 2am-9am (but hourly outside of this timeframe). Ideally, I'd like to have this in ...
0
votes
0answers
4 views

Power/Session -> New Session from bash script (KDE)

I would like to ask, probably trivial question, yet I was unable to find what is required. Suppose I click Power/Session->New Session from launcher, KDE gives me possibility to login as another user. ...
0
votes
0answers
18 views

How to execute shell script in remote windows machine [duplicate]

I have a shell script which will be useful to download the jars from ftp and copy it in a particular location and do some deployment stuffs.. I need to run the script in remote Linux and windows ...
1
vote
2answers
37 views

Copy output of curl to file

I'm running raspbian and using this bash script to take a photo every minute and upload it to my FTP server: #!/bin/bash while [ 1 ]; do DATE=$(date +"%Y-%m-%d_%H_%M_%S") raspistill -q 10 -th none ...
0
votes
4answers
48 views

Find files using shell script

I have the below script which looks for the file in the current directory and evaluates to true if the file exists in the directory and evaluates to false if it does not #!/bin/bash printf "\n Please ...
0
votes
2answers
30 views

How to seperate executable calls as different functions in shell script?

This is what I would like to achieve. #!/bin/bash function startBasics() { gnome-terminal -e "sth" & gnome-terminal --tab -e "sth_else" & } function doOneThing() { ...
0
votes
1answer
67 views

How to crash a Linux PC at a specified time? [on hold]

I am working on a security use case where a linux PC can fall in the hands of an enemy who may gain access to the system (asking password at gun point) etc. I am looking for a technique (a short ...
1
vote
1answer
63 views

Looping through lines in file using bash and passing to variable. Resulting variable is not the same value as file, why?

I have a bash script (just doing some simple log file pattern matching) that I have had running in a cron for a few years. Recently it broke and started returning odd results. Upon digging into the ...
0
votes
1answer
33 views

Run a job inside a shell and check if it completed successfully or not? [on hold]

I am trying to run a program inside a shell, whilst writing some information about the program into a file (pid & completed with error or not? if 0 completed successfully else, completed with ...
5
votes
5answers
338 views

BASH: how to pass a default argument if no arguments after the first were passed

I have a bash script with a case statement in it: case "$1" in bash) docker exec -it $(docker-compose ps -q web) /bin/bash ;; shell) docker exec -it $(docker-compose ...
4
votes
2answers
188 views

shell script to make directories, subdirectories and files following a pattern

Is it possible to create a script that will create the following structure after running it: /test/1/1 -> A /test/1/2 -> B /test/1/3 -> C /test/1/4 -> D /test/1/5 -> E /test/1/6 -> ...
0
votes
1answer
24 views

Extracting two values from the output of a command [duplicate]

I have a script that conducts a Whois lookup on each domain in a list and I need to extract the creation date and the expiration date. I have the first part but can't seem to get the expiration date ...
1
vote
1answer
76 views

How to write bash script without using sudo in it?

How can I write a gem install or apt-get install in bash without letting it use sudo? #!/usr/bin/env bash apt-get update -y apt-get upgrade -y gpg --keyserver hkp://keys.gnupg.net --recv-keys ...
-1
votes
0answers
41 views

Professional IDE for editing bash script [closed]

To develop bash scripts for Linux systems. What are the good IDEs (Syntax suggestions available IDEs) to use as professionals ? I am using Basic editors like Vi, gEdit, Nano etc.. When we are ...
0
votes
1answer
34 views

cURL: Request to http and https by default

A server is running on 5000 port. I have to write a bash script to cURL that URL and parse the response. Here the problem is server can run on either http or https protocol. That means I have curl ...
1
vote
1answer
32 views

Double quotes issue in bash script

I have a shell script I am trying to get working. I need the output to be a certain way and I know I'm just not escaping the characters correctly. script: #!/bin/bash set -x DATE=$(date ...
1
vote
1answer
36 views

Test length of string in file

I am not sure if I am using my argument correctly. I would like to pass in a argument which is a text file containing a string. When I run this script, it always enters the if statement even when the ...
-1
votes
2answers
34 views

change permissions

I am practising and I am trying to: 1) create files with name of all combinations or r,w,x permission = 512 files; 2) change the permission of that file to match the name I have created this ...
0
votes
1answer
17 views

grep -E with parameter doesn't work

If I use -E option for grep from a script I'm unable to user variables. For example: txt file: word nir asd b asd text script: #!/bin/bash PARAM=b cat txt | grep -E 'nir.*${PARAM}' The script ...
3
votes
3answers
39 views

How to pipe data from one command to another command which allows only a file as an argument?

I have some arbitrary data as an output of a command (e.g. a fragment of a binary data put out using tail). I want to feed it to another command/program which allows only a file as an argument (e.g. ...
7
votes
1answer
117 views
+50

Need help improving my Bash script

I need some help improving my Bash script so that it runs flawlessly without having issues. This script uses ds4drv in it and it has some issues that I'm unsure on how to correct. First issue is that ...
0
votes
0answers
23 views

if statments within bashrc [closed]

I've got a few different terminals install on my Linux system, - terminology, terminator, ETerm, URxvt, etc. I'd like to know how to write a proper if statment that will know which terminal is being ...
-5
votes
2answers
33 views

Find files that match a certain size and modification time?

How can I find all the files in directory greater than a certain size, say, 15 KB, and which have been modified in the last 10 days?
2
votes
2answers
51 views

How do I remove all but the last occurrence of a string?

I am trying to remove all occurrences of 2016/01/30 14:52:51: but the last one. I tried this: awk '{gsub(//,"2016/01/30 14:52:51: ",$1);print}' to replace all but the last occurrence with nothing, ...
1
vote
2answers
26 views

BASH - Associative array - getting the value of the key in the final element

I have created an associative array as follows: declare -A test_array test_array[0,0]="1" test_array[0,1]="A" test_array[0,2]="11" test_array[0,3]="AA" test_array[1,0]="2" test_array[1,1]="B" ...
3
votes
1answer
26 views

how to read variables in bash and pass these variables to a c++ program as arguments

I am trying to read a few vars in my bash script and pass these to a C++ program which will accept these variables as arguments. any help please? I got this far..but it does not work... echo -n ...
1
vote
3answers
52 views

Shell Scripting: calculate power of a number with a real number as an exponent

I am using shell scripting and I am using the following expression: A=`echo "(( (($a / $b) ^ 0.3) -1 ))" |bc -l` I want to have a real number as an exponent. I noticed that If I place 0.3, it ...
0
votes
2answers
66 views

How to cut every line from a particular string?

input.txt: john_Apple01_xyz_1 john_Fruit_Apple01_abc_c1 john_Apple21_trs_1 john_Fruit_Apple21_efg_1 john_Fruit_Apple21_tefg_1 Desired output: Apple01_xyz_1 Apple01_abc_c1 Apple21_trs_1 ...
1
vote
1answer
31 views

echoing a value from a BASH function after a command has been run in the background

I am trying to run the following, as a test for something else: function echo_test { sleep 60 & > /dev/null returnpid=$! echo $returnpid } pidthatwasreturned=$(echo_test) echo "This ...
3
votes
1answer
39 views

How to get a randomly shuffled sequence based on shuffle intensity indicator?

I need to get a sequence of shuffled elements in a range, but I want to determine how much this sequence should be shuffled. For example, suppose our range is 1-100 and I want a sequence of 10 ...
4
votes
1answer
56 views

How to remove a positional parameter from $@

Basically, I want to "pluck out" the first occurrence of -inf from the parameter list. (The remaining parameters will be passed along to a different command.) The script I have has the following ...
1
vote
1answer
45 views

Implement a shell in a bash script [closed]

I am trying to emulate a shell in a bash script, like this: cmd_shell() { while true; do read -e -p 'pass> ' command run_cmd $command done } It works ok, and the option ...
-1
votes
1answer
23 views

script for automount, using if statement. cannot got the result [duplicate]

This script should auto mount a file system on a Linux server. testcheck=`df -h | awk '{print $6}' | grep "/test"`; if [$tescheck -ne "/test"] then mount /test else echo "failed"; fi I'm ...