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

learn more… | top users | synonyms (2)

0
votes
1answer
19 views

For loop separate $i's [closed]

Hi I want to have "NOTHING HERE" to come out of the for loop but I get NOTHING and HERE pi@ed_pi:~ $ cat test.txt NOTHING HERE pi@ed_pi:~ $ for i in `cat test.txt`; do echo $i; done ...
1
vote
2answers
37 views

Script to Organize Desktop into Folders/Directories by Extension

I'd like to organize desktops by running a script that places all of your files into folders by extension. I found some code through googling and the code I found creates a folder with the name of the ...
0
votes
2answers
36 views

script not reporting service status correctly

I have a script that I use for iperf to be able to start, stop, and check the status of it like a typical service. If I issue a "service iperf start" or a "service iperf stop" it works correctly. When ...
-4
votes
1answer
34 views

find problems again? [closed]

How do i show pipe or socked files from a directory? echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find $directory -maxdepth 1 -type ...
-1
votes
0answers
15 views

find command problem [duplicate]

I want to show the subdirectories of the given directory that have been accessed by the 'x' last days when x a argument of mine! echo "give name of directory: " read directory if [ -d "$directory" ...
-1
votes
0answers
29 views

find(shell script problem )

I want to show if the files of the given directory changed contents during a specific time period and I want to be able to set that time period as an argument. echo "give name of directory: " read ...
0
votes
3answers
67 views

`Syntax error: “(” unexpected` when creating an array

I have two (Debian) Linux servers. I am creating a shell script. On the first one I create an array thus: #!/bin/bash target_array=( "/home/user/direct/filename -p123 -r" ) That works fine. ...
0
votes
2answers
29 views

Shell script - blanks are not always recognized as such?

I'm confused on how bash interprets blanks while executing a script. In the end, I want a script that is fed by a csv file containing software used by an organisation and it should return the CVEs for ...
0
votes
3answers
21 views

problem with find (shell script)

I want the files of a given directory and use the following script: echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find /-type f ...
1
vote
2answers
37 views

cd in bash script without alias, function, source [duplicate]

I have a little problem, and hope that anyone can help me. I've written a bash script which should cd me to a directory. My problem is that only the directory in the subshell changes. I've read of ...
0
votes
0answers
26 views

Track command line with timestamps

I want to create a program that audits the command line I/O of a terminal session using its PID. I found out about script command which is pretty much the same to what I want, but the problem is that ...
0
votes
1answer
24 views

Execute a init script from C++ program

I have a script in my /etc/init.d/ which executes an application. I am able to start,stop and get status of the service from terminal. Now I would like to start the same service from my C++ program. ...
3
votes
2answers
77 views

ifdef style conditional inclusions for shell

Consider the following script. #!/bin/sh echo "" | ...
3
votes
1answer
39 views

how to remove 0 (zero) from the day and month but not from the year (01/09/2012) using in Linux (Redhat)

Using Linux (Redhat) I need some help regarding the a/m request When I use dialog: --calendar to output the date. The format will be dd/mm/yyyy but I need the format to be d/m/yyyy for day and month ...
-2
votes
2answers
79 views

How do you remove newline character in the middle of file?

File structure: Col1|Col2|Col3|Col4 123|456|abcdefg Tel.: 689346589934, xyz lckhasfkl|abc I want to remove the newline character from 'col3' only.Please suggest
3
votes
3answers
68 views

while read line in shell script - how to stop the loop?

I read a tutorial here that I can use while read line do wget -x "http://someurl.com/${line}.pdf" -o ${line}.pdf done < inputfile However this script keeps running with $line not containing ...
1
vote
3answers
73 views

Add line to configuration file from a bash script?

I am trying to figure out to locate a line in a configuration file, then to drop down two lines then to insert a line of code. I was attempting to do this in awk/sed but got stuck on the carriage ...
1
vote
2answers
55 views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
0
votes
0answers
34 views

Fetch data from a CSV file based on multiple conditions

I'm trying a write a generic shell script which should extract data from a CSV file based on multiple conditions (generic) and write it to another CSV file. Sample CSV file: ...
8
votes
4answers
178 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...
13
votes
1answer
343 views

Where are bash line continuations after && and || documented?

I have seen this construct in scripts a lot and used it myself, but it bothers me that I can't seem to find it in the documentation. Example: [ -f file1 ] && [ -f file2 ] && echo ...
0
votes
0answers
31 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
30 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
53 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
37 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
28 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 ...
0
votes
3answers
72 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
53 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
27 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}') ...
1
vote
1answer
45 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 ...
1
vote
1answer
48 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
166 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 ...
0
votes
1answer
27 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
238 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
44 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
63 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
14 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
20 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
128 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
60 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 >> ...
-2
votes
1answer
27 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
38 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
119 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
22 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 ...
5
votes
5answers
265 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
52 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
121 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
348 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
47 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 ...