New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

Help with simple program for terminal


Post Reply New Thread Subscribe

 
Thread Tools
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
I am new to MAC's for the most part. I want to write q quick small program to change directory and execute a command string. How can I write and compile this file so I can execute it from terminal? Something simple like -

cd ~/desktop/temp
./something -1 blah blah

I know this should be pretty simple. In the PC world I would just create a bat file.

Thanks!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Simply put those commands in a text document (make sure it's plain text). Open up terminal and type the following to make it executable:
Code:
chmod +x <name of file>
Replace <name of file> with the name of the file. All you have to do now is execute it like you would an application:
Code:
./<script name>

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
Thanks I knew it was simple, just didnt have the syntax.
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
Ok as simple as it may be, I cannot get it to work. How do I write a text file to convert that will do this -

cd ~/desktop/sample

./sample commands blah blah


I want to do two things, change the directory and then send a command how do a format the text file so I can do the chmod on it? I started by seeing if I could just create the file to change the directory and it doesnt work. I open the text editor on my MAC, changed preferences to make sure it was text and not rtf. I then created a text file called test.txt that had this one line in it -

cd ~/desktop/temp/


I save it, did the chmod +x on it, ran it ./test.txt from the desktop in terminal and nothing happens....

Help?

Thanks
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Create a file with no extension with the following:
Code:
~/Desktop/sample arguments
Then make it executable:
Code:
chmod +x <script name>
Finally, execute it. You don't need to change directories if you use the full path when executing the application.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
It all seems pretty simple but it is not working. Here is exactly what I am tryin to do. I am trying to create a small executable file I can use to reboot my ATV which I jailbroke. The command and arguments is pretty small but I was just trying to simplify the procress. I need to make a small executible file that does this -

directory with files is ~/desktop/tethered/

file and arguments is -

./tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

I wanted to store the file in my root directory so I could just fire up terminal and type ./<filename> and it would go to the right directory and send the command and arguments. Why is this so hard? It probably isnt!

Thanks
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
You're going to have to help me out here - what isn't working? The steps I outlined should work and without knowing what's not working, I can't help any further.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
Thanks.. here is what I have.. The files are in directory -
/desktop/tethered/

The file to execute with arguments is -
tetheredboot

so I type exactly this and only this into a text file -

~/desktop/tethered/tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

I save it as 'test' with no extension and then do the 'chmod +x test'

When I execute the file from the desktop in terminal I get this error -

Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu'

But to double check it 'should' work. I open the 'tethered' directory in terminal and type 'tetheredboot' with that same argument string as listed and it works.

Why?


EDIT:
If I copy the new script command into the 'tethered' directory it works. So the path in the script works to the point that it points to the file 'tetheredboot' because its trying to execute that command, but it fails unless its executed from the same directory. Why?
QUOTE Thanks
McYukon

 
McYukon's Avatar
 
Member Since: May 14, 2009
Location: Near Whitehorse, Yukon
Posts: 2,053
McYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to behold
Mac Specs: 2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9

McYukon is offline
Try this,
cd ~/desktop/tethered; tetheredboot -i iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

Use the reputation system if a post helps you!
Mac Forums IRC Channel - Help build it by hanging out with us
The next sentence is true. The previous sentence is false.
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.

Also interesting observation... as I mentioned the new script works when executed in terminal from the directory it resides in, but when executed from anywhere else it says - Cannot open iBSS file 'iBSS.k66ap.RELEASE.dfu' .. Now if I execute that script by double clicking the script file right in FINDER and not through terminal I get that same error. This tells me that when executing the script in terminal from any other directory its is as if the command is not being sent in terminal mode... does that make sense?
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
Put the full path to the iBSS.k66ap.RELEASE.dfu file as well in your script:
Code:
~/Desktop/tethered/tetheredboot -i ~/Desktop/tethered/iBSS.k66ap.RELEASE.dfu -k kernelcache.release.k66

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks
McYukon

 
McYukon's Avatar
 
Member Since: May 14, 2009
Location: Near Whitehorse, Yukon
Posts: 2,053
McYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to beholdMcYukon is a splendid one to behold
Mac Specs: 2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9

McYukon is offline
Quote:
Originally Posted by NOYB111 View Post
Doesnt seem to work. Now it doesnt even seen the tetheredboot command so its not even looking in the directory at all when I do that.
Well I was just trying to help with my somewhat limited Terminal knowledge, but it seems vansmith knows more about it

Use the reputation system if a post helps you!
Mac Forums IRC Channel - Help build it by hanging out with us
The next sentence is true. The previous sentence is false.
QUOTE Thanks
NOYB111

 
Member Since: Jan 09, 2011
Posts: 7
NOYB111 is on a distinguished road

NOYB111 is offline
That worked once I also added the path to the second argument. For convenience I also changed the directory to 'boot'. This is what worked -

~/boot/tetheredboot -i ~/boot/iBSS.k66ap.RELEASE.dfu -k ~/boot/kernelcache.release.k66

Thank you very much for the help. Do you happen to know of any good sites to learn basic script writing?

Have a good one!
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,350
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
None in particular but searching for bash scripting in your search engine of preference will no doubt yield many results.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks

Post Reply New Thread Subscribe


« Time machine question | Using Go while another program is up »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Help running program called REEBOX weirdtommyro OS X - Apps and Games 1 11-24-2010 01:46 AM
a simple program to edit video clips? christoh OS X - Apps and Games 4 11-05-2010 03:38 PM
Graphics program help lbrewer42 Images, Graphic Design, and Digital Photography 0 01-02-2008 01:05 AM
Playing with pics on my Mac: Simple Questions. Pls help! :) MacNewbie Images, Graphic Design, and Digital Photography 4 10-27-2007 07:36 PM
Simple AppleScript request... 570thusaag Running Windows (or anything else) on your Mac 0 02-02-2006 01:33 PM

All times are GMT -4. The time now is 10:28 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?