Solved

How to execute the shell script on Mac Terminal: Command output?

Posted on 2015-01-17
7
192 Views
Last Modified: 2015-01-24
Hi,
I'm running a .sh script to several files on Mac Terminal. The script and the files are saved in the same folder. The script looks good for the command "chmod +x script.sh". However, the output was not shown on the terminal. Just wonder what is going wrong here. Thanks.
0
Comment
Question by:skyberrie
  • 4
  • 2
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40555008
What was in the .sh script, how did you run it, and what output did you expect to be shown?
A chmod command does not normally produce output unless there was an error.
0
 
LVL 18

Expert Comment

by:SimonAdept
ID: 40555718
+1 to ozo's reply. Add 'ls -al' to the end of your script if you want to check the results of your chmod command.
0
 

Author Comment

by:skyberrie
ID: 40555976
Please see the attached script. I have tried by adding 'ls -al' at the end of the script but it doesn't work too. Thanks.
Script.sh
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40555984
When I run that script, FileName is never set, so I get
1292860800
1294119000

The file exists

The file exists

The file exists

The file exists

...which continues for a very long time

Perhaps you meant to say
site="A"
instead of
site=“A”
When I make that change, I get a long list like
1292860800
1294119000
Data1_2010_12_20_0800.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0830.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0900.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
Data1_2010_12_20_0930.dat
The file dosn't exist
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 500 total points
ID: 40555988
Actually, that's not quite true, the above is what I get when I run it under Linux, after stripping \r characters.
When I run it as is under OSX, I get
: command not found: line 2:
: command not found: line 6:
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]


: command not found: line 11:
Script.28598569.sh: line 26: syntax error near unexpected token `elif'
'cript.28598569.sh: line 26: `elif [ $site = B ]; then

After stripping \r characters, and changing
site=“A”
to
site="A"
I get
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]


usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Data1____.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
Data1____.dat
The file dosn't exist
Script.28598569.sh: line 38: ./Blank: No such file or directory
...
because the -d option to the date command means something different under OSX
0
 

Author Comment

by:skyberrie
ID: 40555992
Thank you. Will you recommend me to run it under Ubuntu?
0
 
LVL 84

Expert Comment

by:ozo
ID: 40556043
Under Ubuntu, I think the -d option means
       -d, --date=STRING
              display time described by STRING, not 'now'
which should make the script behave as described in http:#a40555984
but I don't have a Ubuntu system handy to verify that.

You should be able to check by running
man date
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now