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

learn more… | top users | synonyms (2)

0
votes
0answers
35 views

Startup Profile Not Running From Bash Script, Only Manually

I'm creating a bash script to deploy CA ITCM (for Mac OSX) and upon completion of the install there is a command that can be ran to start all the services so that a reboot is not required. The command ...
3
votes
1answer
43 views

How to detect the architecture of the chroot from inside the chroot?

Let's say for example the host system is running Debian amd64. And on that system, another Debian i386 has been installed inside a folder using debootstrap. Then assume a shell script is running ...
1
vote
3answers
85 views

Find Directory if Number of files is over X

Am wondering if someone can advise on the best way to do this. In my Web Dir is around 100 folders; each folder is a clientID. Within each ClientID folder is a Sub-Set of folders. In each subset ...
2
votes
1answer
110 views

Inline debug (xtrace) in scripts

Is there a way to force enable or disable debug (xtrace) per command line in scripts ? In Windows Shell ("ms-dos") is an "@" which can prefix a command line, disabling that line to be showed if the ...
1
vote
1answer
103 views

How to have netcat server close after n seconds

I need to use nc in a weird way, where I want the server to first send a file, and then recieve a file, and this repeats. I would like to have every instance of the server server close after some ...
1
vote
3answers
916 views

How to display size “human-readable” in lsof | grep /var* [duplicate]

I am currently trying to see , all the files which are using /var mount. With lsof | grep /var* when Its displaying size in bytes. How can I display file size in MB. Thank you.
2
votes
2answers
68 views

SOLVED: Shell Script cant run man command

I have a script that runs commands & takes a screen shot. I want the man file to display & grab a screen shot of it. My script works for the commands alone but if I add "man " before the ...
0
votes
0answers
52 views

Tmux displays “<xzy not ready>” in the status bar

I'm using iTerm 2 nightly and I have the following tmux config setting for the left status bar: set -g status-left "#[fg=green]#h @ #[fg=cyan]#(extip | awk '{print \"ip \" $1}') #[fg=yellow]#(...
1
vote
1answer
68 views

Setting env variable through script on current session

Is there a possible way of setting env variable through script on current session. I have tried source option. But this works on the shell not through script. here is my script content source /etc/...
1
vote
1answer
57 views

substitute from beginning of line with 1 of multiple patterns to the end of another line with 2nd pattern

I have a file like this: data data data $globaltext blah gibberjabber somemorestuff etc ); data data data $otherjunk yada gibberish etc etc more etc ); My desired result is this file: data data ...
3
votes
7answers
182 views

How to insert a string in array with different manner

I have a string like below. str='014387650' Now i want to split this string like below and put the value in the array. A[0]=0 A[1]=01 A[2]=014 A[3]=0143 A[4]=01438 A[5]=014387 A[6]=...
0
votes
1answer
38 views

How to run command after entering postgres

I am trying to execute ls after opening a new Guake tab and logging into postgres. guake -n guake -e 'sudo -i -u postgres && ls' The command successful opens a new tab then prompts me for ...
5
votes
1answer
281 views

Why does commenting out this line in a shell script (using pdftk) cause problems?

Consider the following simple shell script (using pdftk): #!/bin/sh echo "" | ps2pdf -sPAPERSIZE=a4 - blank.pdf pdftk \ A=blank.pdf \ B=blank.pdf \ C=blank.pdf \ cat A C \ ...
0
votes
0answers
68 views

!-2 not found when using alias [duplicate]

I'm lazy, so I like to make a LOT of aliases for some of my most common shell commands. I use the command sudo !! quite a bit to tack on sudo for root access, but when I use the following in my ....
1
vote
2answers
50 views

Bash - non-numeral arguments to [] operator(array)

I have a small script below; however, I don't quite understand the for loop and if statement. First, let's take a look at script: listFieldNumbers () { for ii in ${!field_number[@]}; do if [ $ii -...
2
votes
2answers
192 views

Is it possible to show rsync output on a single line?

I have a bash script that is rsyncing a large directory and the --progress function is great, but is it possible to show all this output on a single line? ie. as the files transfer, just spit it the -...
1
vote
0answers
16 views

Autoloading a particular driver, based on a detected specific kernel

I need some help in writing a tiny script and determining its placement within Debian 7.9 filesystem. As the title says, the script needs to be executed automatically on startup and, after checking ...
0
votes
0answers
24 views

How do I execute a command if a drive is not mounted?

I am trying to create a shell script to mount a LUKS volume if it is not already mounted. The LUKS password will be in the shell script. The shell script is being stored in a encrypted folder so it is ...
2
votes
1answer
171 views

bash while/read loop behaves differently in a mips/musl/busybox based VM

On a musl/busybox based system running in qemu (mips), the script #!/usr/bin/bash printf '%s\n' "${BASH_VERSION}" > test.txt echo 'test.txt:' cat test.txt echo "No process substitution:" while ...
3
votes
1answer
65 views

Bash append to file, removed during execution. Can this be fixed?

I just realised something rather stupid (my side) happened. I am currently running multiple programs on several machines while appending their output. E.g. machine01 is running "./calc 1 >> calc_one....
-2
votes
1answer
33 views

How to pass arguments of the shell script when calling it?

#!/bin/bash ./bbmap.sh ref=ref.fa # creating index file from the input for $i in {ls*.fastq} # trying to run batch processing do ./bbmap.sh in=$i out={.} done It says: BBMap version 35.74 ...
1
vote
1answer
65 views

Find oldest directory name on a remote server?

I'm writing a backup script of sorts. My backup server contains 3 directories (named by date in the MM-DD-YYYY format) For example: 12-22-2015 12-28-2015 12-29-2015 Im writing my backup script ...
0
votes
2answers
168 views

Why does the parameter $0 give me only the basename instead of full path after converting x-shellscript to x-executable?

My problem here is that the parameter $0 gives the same result as ${0##*/}, and that happens after converting the x-shellscript to x-executable using the SHC program! OS: Debiab-8.2-jessie SHC ...
1
vote
1answer
120 views

mpack description (-d) from a script variable

In my script I have a variable named $message. I want to send this message together with a jpeg using mpack. One way that works: echo "$message" > myText mpack -s "test mail" -d myText myImage....
5
votes
5answers
446 views

Rename files based on their parent directory using find/xargs command?

I have a directory structure like this: Project/ | +--Part1/ | | | +--audio.mp3 | +--Part2/ | | | +--audio.mp3 | +--Part3/ | | | +--audio.mp3 ... I want to ...
0
votes
1answer
54 views

modify all of the files to read something other they what they do

the Objective is to write a proccess that literates through a tree then change the names of everything within that tree including the names of the tree itself (the leafs, the branches, and trunk of ...
2
votes
2answers
1k views

What is the difference between kill , pkill and killall

I am familiar with kill command , and most of the time we just use kill -9 to kill a process forcefully , there are many other signals that can be used with kill. But i wonder what are the use cases ...
3
votes
4answers
367 views

How do you create a for loop with a changeable number of iterations?

How do you iterate through a loop n amount of times when n is specified by the user at the beginning? I have written a shell script and need to repeat a certain part of it n numbers of times (...
3
votes
1answer
72 views

Dropping a connection upon event

Is it possible to drop a number of connections when establishing new ones? For example, suppose we have a set of remote workstations with addresses {A, B, C} and another set with hosts {D, E}. We ...
3
votes
2answers
146 views

Find all files modified around a known one

An installer which isn't really clean (Adobe Acrobat Reader DC) installed on my Unix (Mac OS X) a lot of files in different places. I have a reference file Application which I am pretty sure was ...
2
votes
1answer
92 views

See if a script is running when using #!/usr/bin/env

I have tried migrating the shebang for my bash scripts from #!/bin/bash to #!/usr/bin/env bash, and some of them were broken because they relied on this code that checks for existing instances of ...
2
votes
2answers
70 views

How to duplicate a file a number of times while embedding an index in each file

I have a file named, for example, ascdrgi.txt, with the following contents: tiger lion cat I want to duplicate this file a (variable) number of times by changing the last character of the filename (...
2
votes
1answer
41 views

Bash scripting to process an experiment data file

I have a .txt file with a sample snapshot of the content shown below. I have to sum all the field values and output them. That is, sum total CEPSDIST (MEAN), sum total SRMR, etc. I want to use bash ...
2
votes
1answer
47 views

Extract URL from non-formatted text

I've found only examples on extracting substrings from formatted text like HTML files, but in my case I need to output a list of URLs for example: ... https://twitter.com/user1/status/xyza https://...
3
votes
2answers
395 views

The type command can't distinguish between an executable command and a shell script

So I was reading the book The Linux Command Line, and it says that commands are of four types: (1) executable programs (2) shell builtins (3) shell functions (shell scripts) (4) ...
3
votes
1answer
76 views

Split line to words of maximum size of 8 characters

I'm creating script that will display 2 times the song name in FM radio station name. Radio station name is limited to 8 characters. Lets say I have this line: Best Direction - I feel good The code ...
-1
votes
1answer
28 views

Comparing values in one same string [closed]

In my script, Im getting data from website, like that: content=$(wget 10.0.1.5:8000/currentsong?sid=1 -q -O -); It's basicaly song information on shoutcast server. But there is the problem: I like ...
3
votes
4answers
130 views

Extracting strings from between special characters

I have a large text file created from combining lots of html files. cat *.html > all_html_files.txt Inside the text file are specfic strings that I want to extract to another text file. For ...
1
vote
1answer
150 views

Unable to store command output in variable

I am executing below script but i get an error "line 14: last-tag=TSTA-6: command not found" i.e. at the point i try to store the command output in variable (TSTA-6 is output of command). Any ideas ...
1
vote
0answers
15 views

Need Help to Solve Screenlock Bypass Issue for Expired User Account

I have created a script that I deploy to my children's computers via Salt. The script implements allowed working hours and has worked well, but one of my children have found a way of bypassing this ...
2
votes
2answers
54 views

Is it possible to display a running timer in a shell script while copying a directory?

So I have a shell script that basicly backs up one server to another server. In the process I have to cp a very large directory (140GB) to another location, in the shell script I would love to have ...
-4
votes
1answer
54 views

How to transform row to collumn in csv file?

2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1 ;pmEs ;0 I need this result 2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1;pmEs;0 Extra data from comment: 2015-12-21 19:30:...
1
vote
1answer
253 views

Bash script to select files to zip/unzip

I'm trying to zip and unzip files with a bash script, but I'm new and I have problems. I will explain what the script currently does, and then what I wanted it to do. User selects “compress”: a file ...
1
vote
4answers
177 views

Extract substring with character instead of position

I recently got into nautilus scripts, and for the one I'm writing I'd need to extract a substrong from a filename. My problem is that I found tons of methods to extract a substring based on the ...
1
vote
2answers
305 views

Prefix and suffix strings to each output line from command

I have ran into a problem trying to write a Bash script. When grep outputs, it returns (usually) many lines. I would like to prefix and suffix a string to each of these output lines. I would also ...
1
vote
5answers
314 views

Add quotation marks & comma to each word in a file

I have a list of words such as: string1 string2 string3 .... string12312 How do I convert them these words in such manner that output could be used as a JS array, i.e. "String1", "String2"..., "...
4
votes
2answers
60 views

How do I find the PID of a particular program?

I would like to write a Bash script that searches for PIDs matching a program's name (perhaps using ps ax | grep <PROGRAM> or something similar) and feeds them to pixelb's ps_mem script. ps_mem ...
-1
votes
4answers
136 views

bash script to reverse line

So i came across this script to reverse an input line #! /bin/bash input="${1}" reverse="" len=${#input} for(( i=${len}-1; i>=0; i-- )) do reverse="$reverse${input:${i}:1}" done ...
0
votes
1answer
57 views

Bash script not working, doesn't change directory

First off, I only just started learning how to use Linux yesterday so my abilities are very limited. I am essentially creating a script that I can run everytime I turn on my VPS and the script then ...
1
vote
3answers
151 views

Find value in one column and print corresponding value from other one

I have text file with values as: 1 Peter 2 Paul I need a command/scipt that will take as a parameter value from the second column (e.g. Paul) and return the corresponding value from the first one (...