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

learn more… | top users | synonyms (2)

1
vote
1answer
113 views

Unreadable backup directory on a USB drive

The title pretty much sums it up. I was editing a script I wrote some time ago to automatically backup the contents of my Raspberry Pi SD card, and in the course of editing, I missed a "/", and so ...
0
votes
2answers
176 views

How to run a command with a hidden password

I need to run a curl command that accesses a website that another person has the password to. e.g. curl --basic --user myfriendsname:friendspassword http://www.updateinfo.com I need a way where I ...
0
votes
0answers
55 views

TAR not excluding directories with date pattern

I've written this small script: #!/bin/bash TODAY=`date --rfc-3339=date` CHECKDATE=`date --date "2 days ago" --rfc-3339=date` FILENAME=$TODAY-package.tar tar cvf $FILENAME --no-recursion ...
1
vote
1answer
36 views

Problem in using user defined variable in a script

The following is a simple script, named myscript, that I wrote in order to run a command. dcmpath='$HOME/Data' dcmfile='IM1' dcm2nii $dcmpath/$dcmfile Unfortunately, bash does not recognize the ...
2
votes
3answers
90 views

Script needs to read echoed line

So, I need to write a Bourne-shell script, where my script has to work with the line, that was just echoed to stdout - e.g.: echo *something* | myscript.sh [parametres...] This may be a basic ...
3
votes
1answer
85 views

Difference between “.” and “./” while setting the environment variables using export? [duplicate]

Please excuse me if I am not clear while asking questions. I will try my best to be very clear while asking questions. While learning Embedded Linux, we are setting an environment for our project. ...
7
votes
2answers
354 views

Check bash/shell script dependencies

Is there a method/command to check for the dependencies of a bash script? In other words, a response to this question : Which libraries should a user install to run the script? I can do this ...
2
votes
1answer
60 views

Grabbing keyboard control in shell script

I have a certain shell (zsh) script which reads one character at a time and performs an action afterwards. In the shell, this is realized by "read -k" in a loop. I want to execute the script as a ...
2
votes
2answers
76 views

Killing background process in bash script when exiting the script

I have a script that tail a file while displaying a clock in the top right corner. I took the clock part from the internet, and it works ok. The entire script is something like (I simplified): while ...
1
vote
2answers
78 views

Create file with specific formatting from directory contents

I am using Solaris and csh. In $home/test there are five files: a.txt, b.txt, c.txt, d.txt and e.txt. If I run % find $home/test/ -type f -print > ../filenames.txt that file will look like: ...
1
vote
1answer
32 views

observing script execution with monit script seems to ignore pipes

I want to have a bash command running in the background and being watched by monit. To get the PID of this process, I found this script on the web and I modified it to fit my commands: (named sdr.sh) ...
3
votes
2answers
32 views

Trigger job only once and only when load is low

I'd like have automatic update of my gtags, but only when the system is idle. To achieve this, I'm using iupdate to watch over the interesting parts of my source folder. But I have a problem with the ...
2
votes
1answer
69 views

Run script after desktop loads

I'm running a script that changes files and installs things and what not on a SUSE computer. One of the scripts that gets run with my script, reboots the computer and when the computer loads back up ...
4
votes
3answers
730 views

Passing named arguments to shell scripts

Is there any easy way to pass (receive) named parameters to a shell script? For example, my_script -p_out '/some/path' -arg_1 '5' And inside my_script.sh receive them as: # I believe this ...
1
vote
0answers
54 views

Cron job running but not establishing tunnel

I have a script which establishes a reverse tunnel on an endpoint HostB. It looks like this: cat tun.sh #!/usr/bin/env bash # Test code /usr/bin/ssh -V 1> /home/userA/bin/tun.stdout 2> ...
1
vote
3answers
276 views

Bash script for automatic tar backup of chosen files and directories

Within a given directory in linux environment, I need to pick all files modified after a certain date (let's say 7 days) as well as all directories (only in root directory, hence non recursively) ...
1
vote
1answer
26 views

check if genisoimage is succesful

I use a script to convert all VIDEO_TS directories to .ISO. How can I check if genisoimage is actually converting it instead of it failling and converting the next folder? After conversion I have a ...
21
votes
2answers
1k views

What does “${-#*i}” != “$-” mean?

In /etc/profile I see this: for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null 2>&1 ...
1
vote
3answers
49 views

Redirect output of a command to two different files [duplicate]

Redirect output of a command to two different files I know I can use tee, but I dont want the output to be printed on the screen I want them to be printed only on the file example : ls > pk.txt ...
1
vote
2answers
102 views

How to properly launch a program and make possible to redirect its running output (stdout and stderr) at a later stage?

The problem is quite simple: I find useful to have the possibility to switch on (and off) the output of some running program in each moment I need. To be more precise I want to be free to redirect ...
3
votes
4answers
151 views

dd remove range of bytes

Given this file $ cat hello.txt hello doge world I would like to remove a range of bytes to end up with this $ cat hello.txt heorld I would like to do this with dd if possible. The reason is ...
0
votes
1answer
112 views

Using Fifo hang script

out="$katalog/out" # wyjscie fifo="$katalog/fifo" # wejscie mkfifo $fifo touch $out [...] #k ./a.out <$fifo >$out & pid=$! [...] # get input line by line loop start echo "$liniain" >> ...
2
votes
0answers
71 views

Why is my inotifywait loop exiting after removing some subdirectories?

i have the following bash script: #!/bin/sh dir1=/source/dir/path/ while inotifywait -qqre modify "$dir1"; do rm -r /destination/dir/path find /source/dir/path/ -name .svn -exec rm -rf '{}' \; ...
0
votes
1answer
129 views

Creating MySQL database and user without password

I am building a set of bash scripts which basically prepare apache virtual hosts, git repositories and other stuff on a cloud server. So far so good, everything is working, but a big problem occurred: ...
5
votes
2answers
262 views

Why doesn't my loop over the output of ls work?

I am trying to feed Directory names into a for loop. My code is as follows: td='/Test/TopDir/' cd "$td" for x in $(ls -d */ | cut -f1 -d'/'); do echo x=$x done The top directory I run this on ...
2
votes
1answer
70 views

cut slice of file based on time when lines are written

i have a process running always with logging file could reach up to 5 giga, sometime i have to take slice of this log based on interval of time (usually i used dd). is there any command in linux to ...
0
votes
2answers
39 views

FTPing to a remote directory

I need to connect to this ftp http://cdiac.ornl.gov/ftp/ndp026b/ and download the files. I did ftp http://cdiac.ornl.gov/ftp/ndp026b/ and it took the ftp prompt but once I entering commands for ...
0
votes
1answer
23 views

What is the format of the data that must be fed to the freetds tool bsqldb?

I need help figuring out how to input my data to bsqldb. I have been looking for a manual or some examples or tutorial but I cant find anything online beside its command line help. I am planning to ...
0
votes
2answers
35 views

Use xdotool in a telnet session

I have to simulate key presses in a telnet session, and everything has to be invoked by a shell script. #!/bin/sh telnet 192.168.1.14 50000 xdotool type "404" However, once the telnet session ...
10
votes
2answers
822 views

Simplest way to comment/uncomment certain lines using command line

Is there a way to comment/uncomment a shell/config/ruby script using command line? for example: $ comment 14-18 bla.conf $ uncomment 14-18 bla.conf this would add or remove # sign on bla.conf on ...
1
vote
1answer
82 views

can't get hello world shell script to run in FreeBSD

Server is running FreeBSD 9.2. Using vim, I wrote the following script called hello: #!/bin/sh echo "hello world" Then I set it as executable: >chmod 755 hello Then I tried to run it from ...
1
vote
2answers
580 views

How can I run a “grep | grep” command as a string in a bash function?

I'm trying to build a command that pipes the results of one grep command to another grep command in a bash function. Ultimately, I want the command executed to look like this: grep -I -r FooBar ...
1
vote
1answer
193 views

wget a file, logging the output and showing the output on prompt

In a bash script, I need to download a file from the web, for doing it i use wget command. I would log the output of wget command, and at "the same time" having the output prompting on terminal. I ...
1
vote
1answer
70 views

apt-get script to update upgrade dist-upgrade clean and autoremove

I wrote this script, #!/bin/bash # if not root, run as root if (( $EUID != 0 )); then sudo /home/jb/bash/update.sh exit fi apt-get update apt-get -y upgrade apt-get -y dist-upgrade apt-get ...
2
votes
2answers
74 views

Sed? Stripping all formatting, i.e line breaks and whitespaces, from a report text file, while masking out certain pieces

I am working on a project in which I need to remove all formatting from a text file including whitespaces and line breaks, then replace any colons with pipes. I've made some headway but I cannot find ...
7
votes
5answers
391 views

List out strings which are substrings of other strings in the list

I have a list of names like so: dog_bone dog_collar dragon cool_dragon lion lion_trainer dog I need to extract out names that appear in other names like so: dragon lion dog I looked through the ...
1
vote
3answers
70 views

Bash Script not deterministic in performing actions

I have a bash script which I invoke on system boot (Ubuntu 10.04) "Startup Applications". script: #!/bin/sh APP1='/home/ipc-display/development/projects/display-mgmt' ...
0
votes
1answer
66 views

Please explain the Awk script provided below

Can anyone please expain me step by step below AWK script written. I have the below code written in my script to format the flat file data. Just wanted to understand so that i can reuse -- I am not a ...
0
votes
2answers
181 views

Bash script returns “command not found” when outside the source folder

under my directory, /home/lucas/bin I have the following script term_multiscreen: [lucas@lucas-ThinkPad-W520]~$ sudo cat bin/term_multiscreen #!/bin/bash # Initializes ...
0
votes
4answers
121 views

What does “while test $# -gt 0” do?

I'm trying to create a function and believe I found a good working example but I don't understand all the logic behind it. More specifically, on the "while" line, could someone explain what test is ...
1
vote
1answer
181 views

Create a iptables rule if the rule does not all ready exist

Hi I've created a script to setup Nagios on my remote servers. My Script checks iptables to see if a firewall rule all ready exists and then is supposed to add the rule if it's not all ready there. ...
1
vote
4answers
85 views

How to delete a line if string is the only thing on the line

How can I use sed or something else to delete a line only if the string I'm searching for is the only thing on the line? Example output: device-address-binding: ? database-revision: 20 -- ...
0
votes
3answers
294 views

XOR of a shell variable and a binary file

I have a password stored in a shell variable (which was read from command line input). I also have a keyfile stored in a file (which was created using dd and /dev/urandom). Since I want to require ...
-4
votes
1answer
58 views

Run series of command independent of each other

If I have a file with cmd1 cmd2 cmd3 And I want to run them independent of each other, and independent whether it outputs an exit status or not (that means do not expect to end, just keep ...
0
votes
3answers
69 views

Creating list of domains using httpd.conf

I am trying to create a bash script that can generate a file which contains a full list of domains - from Apache's configuration file - that a web server hosts. It actually seems quite easy. From ...
6
votes
1answer
114 views

Determine dynamically allocated port for OpenSSH RemoteForward

Question (TL;DR) When assigning ports dynamically for remote forwarding (a.k.a. -R option), how can a script on the remote machine (for instance sourced from .bashrc) determine which ports were ...
0
votes
1answer
32 views

Expansion of *,#,% - What do they mean? [duplicate]

for j in * .* ; do cp $j ../$name-S$i.gid/${j%%. * }$i.${j#*.} done Could someone tell me what this for loop does? What do *, % and # mean? ($name is a path of a directory in which there are ...
3
votes
3answers
129 views

How to call a shell function

How can I use the integer value returned by a function in shell script that takes some arguments as input? I am using the following code: fun() { echo "hello ${1}" return 1 } a= fun 2 echo ...
1
vote
1answer
122 views

What does “if [ -e $name ]” mean? Where $name is a path to a directory

In the if [ -e $name ], what condition check is -e? $name is a variable of a path to a directory.
0
votes
1answer
51 views

Trying to pass user generated variable to an external command

I have a bash script that is asking a user for input, then passes that variable to a find command. I've tried quoting/escaping the variable every way I know, but it keeps failing. read -p "Please ...