Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
2
votes
1answer
19 views
How to perform the watch command onto expression with pipes?
I learned today the wonderful shuf command:
ls | shuf
shows me a listing of the working direcotry, but thanks to shuf each time I execute this piped command expression with another order.
So I ...
1
vote
1answer
25 views
How to copy a file several times into randomly choosen paths within the filesystem?
I have a filesystem and a special file foo.
I would like the script to choose several times (5,10 or 100) random paths to folders within this filesystem and to copy the file foo into each of them.
...
2
votes
2answers
45 views
How to take variables from another Makefile in shell script
I want to use the variables from another Makefile under the directory ~/kernelbuild/linux-3.14.37 in my own shell script.
Following is the variables that I need:
VERSION = 3
PATCHLEVEL = 14
SUBLEVEL ...
-4
votes
0answers
36 views
Bash scripting: I am moving one hour old log files from host to rackspace cloud storage [on hold]
I am working on the cloud, using turbolifter to move one hour old log files from my server to rackspace cloud storage but it is not working due to a python issue.
Therefore I'm using this script, but ...
1
vote
1answer
66 views
regular expression to extract information in shell script
I would to grep certain parts of some shell command output in the shell script:
$ uname -r
>> 3.14.37-1-lts
Where I just need the 3.14.37.
And also for the shell script variable VERSION that ...
0
votes
0answers
29 views
How do I realize a Shell Script that keeps track of how long the keyboard has not been used ?
Is it possible to write a script that counts the time between two pressed keys, so that one could put a script into the crontab that checks if the keyboard had not been for longer than a certain time ...
0
votes
1answer
34 views
Syntax Error: unexpected end of file — Bash script [on hold]
I am trying to create an spritz app. Everything was working fine, but since yesterday I keep getting this error: ./spritz: line 176: syntax error: unexpected end of file
I have checked the script ...
3
votes
1answer
21 views
Moving sub-directory to new parent directory where the new directory name is incremented by 1
I am attempting to move a sub-directory from one parent directory to another for hundreds of instances, while changing the name of the sub-directory during the move. My directories are a set of ...
2
votes
4answers
79 views
Calling scripts from inside other scripts
I have a script which I call every 10 minutes with a cronjob:
*/10 * * * * ~/mydirectory/myscript.sh
Now, inside ~/mydirectory there is also another script, let's say myotherscript.sh which I'd ...
0
votes
1answer
47 views
Why are my variables not reset to zero?
In the below loop, I try to reset the values of two variables (totalentries and totalusedbytes) to zero, but I can see from the results that it never happens. Thus each loop continues to add to the ...
-2
votes
3answers
33 views
Syntax error when trying to cut part of a variable
If I write a simple echo $i, I have no problem: it shows me the variable. But if I try do something with it
$($i|cut -d"." -f1-3)
then I get an error messages
: -bash: /...file.backup: Permission ...
2
votes
4answers
52 views
Does it make a difference (e.g. performance-wise) if I execute a command from a bash script (vs the command line)?
Is there any difference between the following (e.g. performance-wise):
$ make && cp bin/myexecutable inputfile.txt $workdir && cd $workdir
$ <series of sed commands to modify ...
2
votes
2answers
61 views
Print file contents and delete the printed content* from the file
In Linux, from a bash shell, how can I print the contents of a file and remove the content I just printed content from the file?
I have a program writing texts to a file repeatedly. On a Linux shell ...
2
votes
2answers
79 views
How to remove duplicate files using bash
I have a folder with duplicate (by md5sum (md5 on a Mac)) files, and I want to have a cron job scheduled to remove any found.
However, I'm stuck on how to do this. What I have so far:
md5 -r * | ...
-3
votes
0answers
33 views
Convert file pattern in Unix
I have a file with content as below
31/01/2014
1234
2234
4567
3321
...n
Need to write a shell script to convert the above file as below:
DD_Date='31/01/2014'
...
1
vote
3answers
38 views
CSV Units Conversion
I've got a CSV file that looks like the following:
miami,20,in
lansing,2,cm
austin,3,mm
chicago,5,miles
phoenix,2,feet
The first field is the name, the next field is the numeric value and the third ...
1
vote
1answer
43 views
Write text on last line of document [duplicate]
If I have this document
aaa
bbb
ccc
And I want to add " ddd" on the last line. My document should look like this:
aaa
bbb
ccc ddd
How can I do this? If I prefer awk or sed but ...
0
votes
1answer
54 views
tar unused files then delete them
I have folder with subfolders and sessions logs. I need some commands or script to tar this folder without usage files and then delete it.
I have this construction, but I'm not sure if this leave ...
2
votes
1answer
92 views
grom() keyword in bash throws unexpected '(' token
I'm not entirely sure why I'm getting the error in my .bash_profile
syntax error near unexpected token `('
when I use the keyword grom() for my function. I wanted to create a bash function that ...
1
vote
1answer
53 views
Brace expansion not working in a script
for i in {1..40}
do
echo $i
done
I got
{1..40}
and I would like to have something like
1
2
3
and so on
so I can use the variable i inside a command's parameter.
1
vote
3answers
76 views
Find result used in if statement
How can I use the result of a find command in an if statement and compare with true or false?
Something like this:
if [ `find . -name test.txt -size 156c`="true" ]; then echo Found; fi
This is ...
0
votes
1answer
38 views
User Input Bash Script
I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could ...
0
votes
2answers
41 views
Its possible use special characters in a shell function name?
I have to create the function in shell script, that function name must contain the special characters. like
>()
{
echo $1 $2
}
Here my function name is >, If its ...
1
vote
2answers
30 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
30 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
2answers
45 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
31 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
47 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
23 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
40 views
What's a way to get the first network interface using grep in ifconfig? [closed]
Just trying to figure this out for a System Administration introduction course, and I can't seem to get it.
0
votes
2answers
99 views
Shell script to execute psql command [closed]
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
41 views
No Such file or Directory 4 [closed]
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
43 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 ...
1
vote
1answer
152 views
how to check the string is Null or not in shell script? [closed]
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
328 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
33 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
23 views
Inserting a text file into a script using cyg-win- did i not claify it well enough? [closed]
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
35 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
21 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
49 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
29 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
21 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
91 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
87 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
47 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
48 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
57 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
37 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 ...