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

learn more… | top users | synonyms (2)

-1
votes
3answers
17 views

.sh query - running a ssh task

This is on a macintosh but its still unix command. I am running some computers on a network that have file sharing turned off because of security so the only way to connect is via ssh. I need to ...
0
votes
2answers
17 views

Issue with the shell script after storing the directory in a variable

FTP is connecting to the server but i am getting an error - Enter if the env is dev or test or prod: test Please enter the id no : xxxxxxx Connected to xxxx 220 (vsFTPd 2.2.2) 331 Please specify the ...
-1
votes
0answers
7 views

Scheduled restart for tomcat server and sending response mail to Admin

I have a script to stop and start tomcat6 service on web servers. Therefore I should add this script to crontab on all the server in order to fulfill the requirement. But this is so difficult to put ...
0
votes
1answer
34 views

Script too slow ? Any particular reason?

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. I also call a python ...
79
votes
2answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
0
votes
1answer
3k views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
1
vote
1answer
19 views

how to inject keystrokes in a program like Safari from a bash script?

I am trying to automate some keypresses every few minutes. The exact timing is still undetermined. But basically I want to capture a live chat dialogue. I'm sure I could do this more elegantly. I ...
1
vote
1answer
40 views

Printing the file with number of hardlinks

I can print the number of hardlinks to files in directory by using find . type f -printf "%f %n\n" but this will also print the hardlink not only original files: Example: file1 is an original ...
21
votes
6answers
47k views

#!/bin/bash - no such file or directory

I've created a bash script but when I try to execute it, I get #!/bin/bash no such file or directory I need to run the command: bash script.sh for it to work. How can I fix this?
32
votes
1answer
3k views

Why does the following bash script delete itself?

If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
3
votes
3answers
99 views

Reverse sequence of a file with POSIX tools?

Is there any clean, clear-cut POSIX equivalent to tac? Readability as well as succinctness should both be considered.
0
votes
2answers
507 views

Unix Shell script to delete all traces of itself after execution through crontab

My Question has 2 parts. Help with both parts is greatly appreciated. GIVEN INFO: - Lets assume there are 2 Folders, Folder A and Folder B. - Folder A contains many files. - Folder B contains the ...
0
votes
3answers
46 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
3
votes
2answers
44 views

Accessing Google-translate via wget

I don't want to call the whole Firefox/Chrome/Opera... to find out the meaning of a word with the Google translate, so I decided to write a shell script which uses wget to get the content of ...
3
votes
3answers
69 views

How to prevent script from deleting itself

Hi I'm creating a recycle bin script with the command name 'safe_rm'. I was wondering, how can I prevent the script from deleting its own file. I believe the readlink command is one solution however ...
1
vote
1answer
25 views

Rc.local not running commands properly

I am running arch Linux and have used this rc-local service: [Unit] Description=/etc/rc.local compatibility [Service] Type=oneshot ExecStart=/etc/rc.local RemainAfterExit=yes [Install] ...
1
vote
0answers
23 views

Access to bash arrays in gnuplot [duplicate]

In a bash script I have several arrays which I need to access in a gnuplot code: #!/bin/bash ... # fill array a[*] and b[*] ... gnuplot <<EOF do for [j=0:10] { # access ${a[j]} and ${b[j]} } ...
-3
votes
1answer
57 views

Need help in a shell script

I need help with the below shell script. I have three environments: test, dev and prod. When the user enters test it should ftp to test host and ftp the file. Same in case of dev and prod. I have just ...
5
votes
2answers
460 views

Create symlink tree in existing directories

I carry all of my music around on a 1TB USB drive and have a udev rule to symlink it to $HOME/Music/ when I plug it in to one of my laptops, which it does. The issue I have is that this works fine ...
-6
votes
0answers
25 views

How to find Multiple strings present inside a file and send a automatic mail if not present [on hold]

I have a requirement like there are 9 strings i need to look for in two files(one has 4 and another has 5). My script should look into those files and notify me via mail if its not present. Hi, let ...
8
votes
3answers
12k views

Why is my variable local one 'while read' loop, but not in another seemingly similar loop?

Why do I get different values for $x from the snippets below? #!/bin/bash x=1 echo fred>junk ; while read var ; do x=55 ; done <junk echo x=$x # x=55 .. I'd expect this result x=1 cat ...
3
votes
2answers
50 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...
4
votes
2answers
3k views

Testing a string containing only spaces (tabs, or “ ”)? [duplicate]

My code below doesn't work: stringZ=" " if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then echo string is blank else echo string is not blank fi Result: string is not blank # wrong ...
0
votes
1answer
29 views

tar directories containing spaces [duplicate]

I want to archive my photos into tar archives. The directory containing photos has one dir per year and multiple dirs inside each year dir: Photos 2005 2006 Some dir with spaces ...
0
votes
0answers
23 views

Fixing Signal 13 Error on find

I have a situation where I'm trying to install softwares into my system. I'm using a fakeroot approach to install them in a separate directory where I'm listing all the files, directories and links ...
1
vote
0answers
10 views

Linux Mint Corners Musical Sequence Associative Array

I am writing a script which uses hot corners to play specific musical notes when hovering in corners, and depending on the musical sequence to execute a specific command. The script is called with ...
0
votes
2answers
34 views

How to use file test to check if a file already exists in a directory

I'm trying to write a script that asks the user if they are sure they want to move a file to a certain directory. The script needs to check if the file already exists in the target directory and if it ...
3
votes
3answers
199 views

Bash replace characters in the output

I need to replace characters in the output of a script but they are NOT in the last printed line. They are in the middle of the output. E.g. ...
0
votes
1answer
55 views

Need help on shell scripting

I need a help on my shell script. Below is my shell script which transfers the file from one server to another. #!/bin/bash echo "Please enter id no : " read input_variable echo "You entered: ...
-1
votes
0answers
27 views

Python to Shell Script? [migrated]

How can I convert this simple python code to Shell script? import time import sys cur_time = int(time.time()*1000) print cur_time sys.exit(1)
-1
votes
2answers
43 views

How to compare two tables and find the difference between in Linux using shell script?

I have two release one is old and one is new. I have to compare old release DB and new release Db and find out all the difference. like if old release and new release have same table so what they made ...
-1
votes
0answers
35 views

How to compare two tables in Linux using shell scripting? [duplicate]

I have two database one is "old-tables" and one is "new-tables". We have made some changes in "old-tables" database. then updated "old-tables" database we are calling it "new-tables" database. ...
86
votes
3answers
51k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
17
votes
8answers
15k views

bash: test if $WORD is in set

I am looking for a construct in bash, to decide if a variable $WORD is one of defined words. I need something like this: if "$WORD" in dog cat horse ; then echo yes else echo no fi does ...
1
vote
1answer
35 views

bash script does not compare file names with [ and ] correctly

I have a bash script that deals with files. It finds all the files in one directory and searches for the name of each in another directory. For that it uses "${myfiletobesearched}" inside the ...
1
vote
1answer
72 views

Pattern matching [duplicate]

I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression. I have the following script: #!/usr/bin/env bash # cookbook filename: ...
0
votes
2answers
19 views

Simple Bash server usign netcat and authorization required [on hold]

Running a simple server in bash: echo -ne 'HTTP/1.0 200 OK\r\n\r\n'; cat page.sh | nc -l -p 8080 The script page.sh generates website. It works and meets my expectations. Is there a possibility of ...
1
vote
1answer
19 views

mv command with path wildcard containing random string

Im trying to move a file to a path which has a random string that I cannot know in advance ~/.config/foldername/45fhiu84.dev-edition/subfolder/ I have tried mv ~/Downloads/myfile.txt ...
0
votes
1answer
28 views

Can all of fork(), exec() and system() be wrong? [on hold]

I understand why it could be less than best practice if I write C code that executes shell commands by calling system() and that it's better to use exec and fork but then a very experienced C ...
2
votes
3answers
68 views

Replace values in file

I have a files: $cat file1.txt 1234|W 1345|S 8427|D 2132|C 3243|V and my sql file is : $cat select.sql SELECT * FROM CUSTOMERS WHERE ID IN (FLAG); and I have a shell with the next ...
0
votes
2answers
35 views

Can we install a package through a shell script? [duplicate]

I'm trying to write a shell script so that when I reinstall my Ubuntu again. I could just run script and retain all the packages. And I'm planning to pass password in form of argument. My question ...
0
votes
1answer
28 views

Script for connection with ssh then command once connected

I need to write a script that connects to a remote server, then once connected, connects from there to another server, then changes directory. The following of course does not work (it connects to ...
1
vote
1answer
50 views

Needed shell script modification to show IP and host DD-WRT

I am running DD-WRT v.3.0 on my Linksys EA6500 router and I have the following script running in order to give me access to the WiFi MAC address that are currently connected to the router: echo ...
4
votes
1answer
823 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
-1
votes
0answers
27 views

Insert the environment path to script file to read [on hold]

I have a text file which has user input i.e LD_LIBRARY_PATH. I want to add the that library path environment text into the script file (/etc/init.d/scriptfilename). Will it be possible?
2
votes
1answer
33 views

Create table with frequency of unique names retrieved from multiple .csv files

I have 32 CSV files containing fetched information from a database. I need to make a frequency table in TSV/CSV format, where the names of the rows are the name of each file, and the names of the ...
-4
votes
2answers
32 views

Linux Bash script fails with a syntax error

Trying to get this bash script to work: #!/bin/bash for result in $(cat ./fn7); for dip1 in $(cat ./fn4); for dip2 in $(cat ./fn5); for dip3 in $(cat ./fn6); for ip in $(seq 0 255); ifconfig > ...
2
votes
3answers
2k views

Update process name in shell, is it possible?

In C/C++ it is in general possible to do strcpy(argv[0], "new process name"). It's a hack used in malicous software to hide real process name. Is such operation possible via shell? What I want to do ...
0
votes
0answers
41 views

Run sh script at system startup - Red Hat 7.2

I searched the Internet but there are too much different opinions about this issue. I have two scripts to run. One to run at system startup (not at system reboot as I read in some posts) and another ...
-3
votes
0answers
20 views

Bash Script problem with Variables from files [duplicate]

Trying to get this script to work how ever I get an error no matter how I try to set the varibles. After checking the varibles are not being set from the files that the information is in.