Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
1
vote
2answers
19 views
Read file remove spaces and store in array
I have a file with the following content:
list:
blue,none
red,none
orange,plot
baseball , none
university,none
school,none
desk,plot
monitor,none
earphone,none
I need to read this file, ...
0
votes
0answers
19 views
How to get and print a user's public IP address in a Shell Script? [duplicate]
I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
0
votes
1answer
28 views
Adding 1 string to end of file, Even when ran multiple times to change MD5
I need to change the md5 of my files, Sometimes once, sometimes multiple times. A friend gave me this script to add a string to the end of the file but i think i may be adding it multiple times when i ...
1
vote
1answer
21 views
Search for text inside java command output
I have a folder which have multiple Jar files.
* dummy.jar
* myjar-xx.jar
* myjar-yy.jar
Using find, I need to find first file starting with "myjar"
Now, I want to grep the contents of ...
4
votes
1answer
40 views
Why does 'jobs' always return a line for finished processes when run in a subshell within a script?
Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions:
$ ping -c 4 ...
2
votes
1answer
22 views
how to connect automatically to a saved list of networks
I want to make my Debian laptop connect automatically to a list of stored WiFi networks in a text file that have the syntax SSID:password, using a non graphical way (script or config).
These networks ...
0
votes
1answer
36 views
What's a way to get the first network interface using grep in ifconfig? [on hold]
Just trying to figure this out for a System Administration introduction course, and I can't seem to get it.
0
votes
2answers
73 views
Shell script to execute psql command [on hold]
I want to make an automated script to make a database user and password in Postgresql and also import some databases. When i execute my script bellow it stops somewhere and when i log out (CTRL+D or ...
-1
votes
0answers
36 views
No Such file or Directory 4 [on hold]
throw the script posted in this question link syntax error near unexpected token `)'
I get this error:
test.txt: No such file or directory
140308719470240:error:02001002:system library:fopen:No ...
0
votes
1answer
41 views
Can a command in a shell pipeline determine the tty characteristics of its context?
I have a bash script that columnizes a list of items. By default it will guess at the number of columns to output, based on the terminal width as reported by stty size. But when the script is in a ...
0
votes
0answers
56 views
syntax error near unexpected token `)' [on hold]
I have written this script on my ubuntu
#!/bin/bash
DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --clear --title ...
1
vote
1answer
149 views
how to check the string is Null or not in shell script? [on hold]
I had a script like this
#!/bin/bash
line="hello"
if [ -z $line ] ; then
echo "String null"
fi
This will work properly, but when I give the lineas follows
...
0
votes
1answer
24 views
sepration of files on the basis of there name
I have a folder containing lots of files like 3 lac plus files. I have to separate them according to their names in three different folders. e.g. a few names are:
7msf_stem_0_mcannotate.pdb
...
4
votes
4answers
318 views
How to fill a file with a stream from /dev/urandom with a specified number of lines ?
I am trying to fill a file with a sequence of random 0 and 1s with a user-defined number of lines and number of characters per line.
the first step is to get a random stream of 0 and 1s:
cat ...
1
vote
1answer
30 views
Using parameters in a script
I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command:
for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...
-1
votes
0answers
22 views
Inserting a text file into a script using cyg-win- did i not claify it well enough? [on hold]
I am writing a script that checks for directories, if they are not there then it is to create them. In two of the directories i need to insert a text file. One of the files has eight comment line and ...
1
vote
1answer
32 views
Test for open TCP port in bash script
I want to delay the script execution until a certain server process is ready, which it is once it accepts incoming TCP connections.
How do I test if a local TCP port is open (I get a SYN/ACK answer)? ...
1
vote
2answers
20 views
Script using sudo works from a terminal but not from a desktop shortcut
I create small script to mount encfs filesystem. just like this:
#!/bin/bash
kdialog --password "Wprowadź hasło do SSH lub ENTER żeby rozłączyć:" > /home/maciek/Pobrane/pass-1
sudo encfs -S ...
0
votes
2answers
46 views
Input in bash script
I have a script like this:
for i in *.TF;
do
my command $i
done
The problem is, each command line needs a same input (in this case: /PS)
how can I do this? I have tested some methods like:
/PS | ...
-1
votes
1answer
27 views
AWK and Bash Scripting [duplicate]
How to use a value of a variable in awk? Something like this:
filename = "test.txt"
ls -l | awk '{ if ($9 == filename) print("File exists")}'
I can't use $ in awk to access the value of ...
0
votes
1answer
19 views
Cron start script twice
I have a backup script which sends my snapshots to a off-site location.
0 0 * * * /root/backup/backup_incremental >> /root/backup/test.log
For some reason my PID file which should stop the ...
2
votes
2answers
81 views
How to delete old backups based on a date in file name?
I have a daily backups named like this:
yyyymmddhhmm.zip // pattern
201503200100.zip // backup from 20. 3. 2015 1:00
I'm trying to create a script that deletes all backups older than 3 days. The ...
1
vote
1answer
52 views
Bash: using both way redirections in a shell script
I'm writing a shell script to compress and backup certain files. This will compress and move large files with sizes up to 4 GB.
I'm having trouble with this line:
gzip < $filelocation > ...
3
votes
3answers
85 views
Delete folders which not match a list
I need practical example how get rid folders which are not in the list in Linux.
So i do not need to compare its contents or md5sums, just compare folders names.
For example, one folder has few ...
1
vote
1answer
43 views
How to Prompt the user to press Enter to Exit in terminal so that the terminal doesn't close automatically?
Here is my Port.sh file
echo 'Give me a maximum of 5 seconds to run please.'
lsof -i | grep Xvnc | grep ESTABLISHED | grep $USER
lsof -i | grep $USER | grep Xvnc | grep -o -P '(?<=:).*(?=->)'
...
3
votes
1answer
47 views
How to poweroff headless machine using a script
I have a Java application that starts automatically when the headless machine (Ubuntu 14.04 Server) boots and runs as a user. When the application is finished I need it to execute a script to ...
-2
votes
3answers
55 views
How to Show your main “shell” that you use.? in UNIX
How to Show your main “shell” that you use.? in UNIX
is this command right
ps -p$$ or if there is a different way?
thank you
1
vote
1answer
33 views
Indented here document causes a syntax error
I have the following code fragment in my shell script and have a bug that I can't seem to pin down a reason for despite some research.
When I run the code as below the script exits with a message ...
3
votes
2answers
98 views
Nested 'awk' in a 'while' loop, parse two files line by line and compare column values
I need some help with a combination of awk & while loop.
I have two simple files with columns (normal ones are very large), one representing simple intervals for an ID=10(of coding ...
0
votes
1answer
19 views
mkvmerge in a bash script does not execute
I have made a script which does mux a videofile, multiple audiofiles and multiple subtitles into one .mkv.
the script tries to run:
"/usr/bin/mkvmerge" -o "test.mkv" "--default-track" "0:yes" ...
-1
votes
3answers
38 views
Error in `for` loop in `if… else` conditions
Hi guys I am new in writing bash script.
I have a task to do. I have a file in which node name and IP addresses are updated, I have to make each file of those nodes which are not in our required ...
1
vote
0answers
19 views
Avoid “Shared connection to <host> closed” messages
I'm managing a lot of drupal sites, and trying to automate some stuff using drush. Drush run locally calls drush on the remote host via ssh using options specified in the config for the site alias. ...
1
vote
3answers
50 views
How can I create a relative symlink given a relative path?
I would like to programmatically find the directory depth of a relative path. So for example the depth of test/dir/hello is 3
More specifically I would like the directory depth so that I can create a ...
4
votes
1answer
18 views
Shell script: filter list of .pdf files, to exclude those with a .tex source file
I have a linebreak-separated list of file paths, all to pdf files. I would like to filter out all those which have a corresponding *.tex file in the same directory (and so can be presumed ...
2
votes
5answers
82 views
How to create a script that can't be easily exited
How would I create a script that does not respond to Ctrl-C? This should also prevent any processes launched by the script from being killed (I'm trying to keep apt-get upgrade from being killed).
(I ...
2
votes
1answer
35 views
Updating config files within the script that references them?
I have no problem adding config files to a given script, but automatically updating them is another matter. In this instance I'm providing a few variables to a script, and I'd like the script to be ...
1
vote
0answers
13 views
How to make svn save credentials when --non-interactive
I'm trying to get svn to save my https username+password to ~/.subversion from within an automated script. I can pass creds on the command-line but I do not want to be prompted about whether to save ...
-1
votes
0answers
32 views
How can I encrypt specific words in a text file with a bash script? [closed]
I want to encrypt same words in a text file and I want to know how I can do it in bash.
For example, if the file contains:
The employee Kim Van, his registration number is ID721 he is work in the ...
1
vote
1answer
36 views
awk with variables in condition and in output redirection file
I would please like some help with this command because I didn't find anything in documentation that can cover everything I want.
I have some variables that are global, so I would prefer to keep them ...
0
votes
1answer
39 views
introduce a c script in a bash file [closed]
My problem is to recover data keyed in text file in bash. I seek the command that can perform this task and I used sed, awk and even cut but I have not succeeded. One friend of mine suggested to ...
1
vote
1answer
9 views
Store delayed shell output to variable?
I have a script which stores output of a command inside a variable like this:
my_var=$(command)
However, some of the output is not being stored in the variable, I am assuming because it is ...
0
votes
0answers
48 views
Where is the log_daemon_msg?
So this is my little shscript (my_init_script.sh) located in /etc/init.d/
#!/bin/sh
. /lib/lsb/init-functions
NAME=my_script_for_auto_update
PIDFILE=/var/run/$NAME.pid
...
2
votes
3answers
80 views
How to run multiple scripts in parallel
I have one bash script which calls the same perl scrips in a serial way. The bash script is used to collect the overall results, while the perl script collects the results of my simulations for the ...
1
vote
1answer
44 views
awk pattern with variable in a bash script
I have problem with command awk in bash
I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line?
awk -F" " "/$PWD/ {print $1,$3}" file.txt
1
vote
1answer
46 views
How to get the http dump of a website and the header both from a single curl command?
I have to fetch a website (multiple redirections possible using -L) and save the html content in a file named as [HTTP_Status_code]_[Website_name].html
Currently I am using two curl calls one for the ...
0
votes
1answer
39 views
Compare text files with grep
Lets say I have two files, I want to find goodbye which I can do with grep but what i'm struggling with is once I find goodbye matching the next line with the first column of file 1.
File1
sss aa ...
1
vote
3answers
26 views
read -e in a sub script
Let's imagine that I have script1.sh and script2.sh with the following sources:
Script 1:
#!/bin/bash
# script 1
echo "Doing some stuff..."
bash script2.sh
echo "Done"
And Script 2:
#!/bin/bash
# ...
4
votes
5answers
94 views
sudo in non-interactive script
I have a script that executes three functions: A && B && C.
Function B needs to be run as a super-user, while A and C doesn't.
I have several solutions but neither of these is ...
0
votes
1answer
19 views
Command for setting DocumentRoot for apache on Debian?
So I am developing a simple installation script for a Raspberry based app. It installs the LAMP install, grants some permissions among other things. And part of the process is to change the apache ...
2
votes
4answers
84 views
Shell Scripting: Proper way to check for internet connectivity?
I found scripts that say they check for internet connectivity. Some check the ip address if the interface is connected BUT it does not check for internet connectivity. I found some that uses ping like ...