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

learn more… | top users | synonyms (2)

9
votes
2answers
163 views

Shell Syntax: How to correctly use \ to break lines? [duplicate]

I used to believe that the appropriate way of breaking the lines in a list is command1 && \ command2 It turned out that it isn't so , one doesn't need \ $ [ $(id -u) -eq 1000 ] ...
0
votes
1answer
69 views

How to pass a parameter with space in nohup? [duplicate]

I have script to run a jar, like shown below. user="Tim Tom"; jarfile=./app.jar SC_CD="java -jar -Xms512m -Xmx2048m -DUSER='$user' $jarfile" nohup $SC_CD And im geeting error message as Error: ...
-4
votes
1answer
35 views

Unpack a shell archive (.shar file)

I have a shell script. How can i remove anything before # this line Everything before the # should be deleted. The script is too long to delete it manually. How can I do that automatically? ...
3
votes
1answer
34 views

If there are more than x number of pipes in a csv line, then delete the 2nd instance

I have a csv file which is supposed to contain 4 columns of data which include a product number, a title, a url and a price. Each column is separated by a | delimiter (this has to be maintained, there ...
0
votes
1answer
37 views

How to maintain only four lines in my file in shell scripting?

Input file: 01.05.2016 87893938 02.05.2016 35435345 03.05.2016 35435345 04.05.2016 12345678 I want to keep only four lines in my file. that means if date 05.05.2016 6905698 is inserted then ...
0
votes
2answers
33 views

Add newline character to file

Hi Guys i need to change the below single line string using a shell script {1:F01NESWSZM0AXXX1111111111} {2:I940BBRUBEBBXXXXN} {3:{108:400MSOG161200FRO}} {4: :20:400MSOG161200FRO :25:1xxxxxxxx65 ...
1
vote
2answers
82 views

sh AND and OR in one command

Trying to check for 3 conditions in one line of code, but I'm stuck. Essentially, I need to code for the following: IF string1 is not equal to string2 AND string3 is not equal to ...
14
votes
5answers
1k views

Compress a large number of large files fast

I have about 200 GB of log data generated daily, distributed among about 150 different log files. I have a script that moves the files to a temporary location and does a tar-bz2 on the temporary ...
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
0
votes
1answer
25 views

custom shutdown script in rc6.d does not seem to be working.

I'm working with a software application that's a bit touchy so I wan't to shut the software down automatically on reboot or shutdown. I have created a script an placed it in /etc/init.d/ with a ...
2
votes
1answer
80 views

Cannot mv to a subdirectory of itself

I am running this simple script and I am trying to create a cron job so that the file gets copied to my thumbdrive (with the new name) sudo cp /home/pi/NewLog.log /media/usb sleep 20 cd ...
3
votes
1answer
36 views

Why does this script not accept two arguments?

Code #!/bin/sh # http://tex.stackexchange.com/a/20886/13173 # http://unix.stackexchange.com/a/280830/16920 # $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $ # Convert PDF to encapsulated ...
0
votes
3answers
45 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
vote
1answer
30 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
41 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 ...
1
vote
1answer
40 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] ...
70
votes
1answer
7k views

Why does the following 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
0
votes
2answers
38 views

.sh query - running a ssh task

This is on a macintosh but it's 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 ...
1
vote
0answers
25 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
62 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 ...
0
votes
1answer
37 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
29 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 ...
3
votes
3answers
106 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.
1
vote
0answers
13 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 ...
3
votes
2answers
73 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 ...
0
votes
2answers
40 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 ...
4
votes
2answers
72 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 ...
3
votes
3answers
84 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
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)
3
votes
3answers
222 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
56 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
38 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. ...
-1
votes
2answers
93 views

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

I have to compare two MySql database data, I want to compare two MySql schema and find out the difference between both schema. I have created two variables Old_Release_DB and New_Release_DB. In ...
1
vote
1answer
41 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
79 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: ...
1
vote
1answer
23 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
34 views

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

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 ...
0
votes
2answers
41 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
38 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 ...
-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.
-4
votes
2answers
33 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
84 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
0answers
22 views

I'm able Start Service With init.d script, however doing service <service name> start does not work

I'm able to start a service with an init.d script, however doing service <service name> start does not work. For e.g. /etc/init.d/haskal start, the service is starting fine and service haskal ...
3
votes
1answer
52 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 ...
0
votes
1answer
20 views

shellscript is having trouble finding a file [duplicate]

I have a shellscript that is having trouble finding a file. The text file exists so I don't understand what the issue is. #!/bin/ksh goodmain $1 | sed -e '1,/mmxxaa/d' $ ls -l total 1364 ...
0
votes
1answer
53 views

Running .sh Script With Sudo Results In Different Output

I'm seeing some really strange behavior in a script I'm working on.What I have is an svn hook that gets run whenever a commit is made to an svn repo. It runs a sqsh command that generates another ...
0
votes
2answers
50 views

How to fix vmware header error?

I'm trying to run vmware on my kali linux 2.0 box, because I want a lab to practice my skills on, but vmware won't launch it's giving my an error message saying "C header files matching your running ...
0
votes
1answer
39 views

If else statement involving two numbers in scientific notation [duplicate]

I have two numbers in scientific notation and I want to do some comparison between them in an if statement in bash. While doing so, I am getting error like bwlow: E.g: bash-4.2$ a=10e-12 bash-4.2$ ...
0
votes
1answer
40 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 ...
0
votes
1answer
34 views

command /opt/bin/date --date '-15 minutes 2016-04-27T14:14:47' producing result many hours before stated time

I'm using the following command in an attempt to work out the time 15 minutes before the timestamp: /opt/bin/date --date "-15 minutes 2016-04-28T16:58:55" '+%Y-%m-%dT%H:%I:%S' The problem is the ...