system admin script

O

Ott Mr

i am trying to find a good scripting language for Mac OS X. I was told
ruby would be a good choice. Before i dedicate my time to learning it I
have to find out a couple of things.


Can you run ruby form the GUI? i.e double click it . I don't want users
to have to go to the terminal.

Here is an example of what i would like to do. We use a package builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

I am more concerned with running it from a GUI. If I can't do that I
might as well stick to shell scripts because I can call them from apple
script which I can run form the GUI. Plus I already know shell
scripting.
 
J

John Joyce

i am trying to find a good scripting language for Mac OS X. I was told
ruby would be a good choice. Before i dedicate my time to learning
it I
have to find out a couple of things.


Can you run ruby form the GUI? i.e double click it . I don't want
users
to have to go to the terminal.

Here is an example of what i would like to do. We use a package
builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

I am more concerned with running it from a GUI. If I can't do that I
might as well stick to shell scripts because I can call them from
apple
script which I can run form the GUI. Plus I already know shell
scripting.

You can make anything executable. But if you want it double clickable,
you might want to wrap it in a simple apple script or use Ruby Cocoa.
You're making a double-clickable tool, so you should give the users
some feedback.

You might even just consider a cron job or use net booting for os x,
or even ARD.

You can wrap any script in AppleScript just like you already know how
to do with shell scripts.
Ruby works just as well, but is much less terse than sh scripting.
Just remember the usual caveats about permissions and such.
For distribution, ctrl click and select 'archive", which will create a
zip, or put it in a disk image (dmg) and that will prevent permissions
issues.

Sounds like you may want to just use sh and applescript, since you
already know it, but you can literally use Ruby the same way.
You could (painfully at times) do the whole thing in applescript, but
that would probably be slow as dirt too.

Almost as easily and much nicer, you can do the same thing from a
simple Cocoa app in Xcode and add a simple GUI to it.

There is also Platypus for wrapping scripts in simply GUI
 
J

John Joyce

Leopard's Automator has a nice tool as well...
in Automator, choose Actions > Utilities > Run Shell Script
and your work flow is almost done.
The "Run Shell Script" workflow includes Ruby in its list. (as well as
each shell and python and perl)
 
P

Phlip

Ott said:
Here is an example of what i would like to do. We use a package builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

In general, in addition to the other answers, I would try this:

- install Ruby on Rails
- write one page
- put one button on it
- install an Authentication plugin
- give your users accounts
- when they click the button, paint a page showing what they did
- deploy your RoR site to an intranet server

We do that at work. Rails is the front-end to our corporate database. Each
feature the knowledge workers need, they request it, and we add it to the Rails
project. The turnaround on this system can be as short as a couple hours for a
new button, or a week for a whole new page.

Classical web systems, such as ASP.NET or Tomcat, are way too top-heavy for you
to consider using them for your in-house administration interface. Don't think
Rails will be like that!
 
L

Logan Barnett

i am trying to find a good scripting language for Mac OS X. I was told
ruby would be a good choice. Before i dedicate my time to learning
it I
have to find out a couple of things.


Can you run ruby form the GUI? i.e double click it . I don't want
users
to have to go to the terminal.

Yes! It doesn't even have to be limited to OS X either. I'd look into
JRuby's Monkeybars library (which includes screencasts): http://monkeybars.rubyforge.org/

You can use a visual designer such as Netbeans to drag and drop
buttons onto the form.
Monkeybars uses JRuby (Ruby for Java), and since Java is installed on
all Macs, you can just push around your app without having to install
any dependencies or making sure you have the right version of the
particular scripting language you want to use. JRuby is just a Java
library, and you can simply package JRuby along with your app.
Here is an example of what i would like to do. We use a package
builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

Yes. With Rawr you simply enter 'rake rawr:bundle:app' at the command
line and Rawr will bundle up your application into a standard Mac .app
file. I have three Monkeybars apps bundled this way that are sitting
on my dock right now.
I am more concerned with running it from a GUI. If I can't do that I
might as well stick to shell scripts because I can call them from
apple
script which I can run form the GUI. Plus I already know shell
scripting.

Ruby has methods of making complicated console calls such as system,
sh, and the backtick (`). For example:
system "cd foo"
system "rm bar"

sh works in a similar way (I believe there is a difference in console
control, and what spawns off as a new process vs. a blocking process.
Don't quote me on that).

sh "cd foo"
sh "rm bar"

Ruby also has a backtick, a literal that's just for sending commands:
`cd foo`
`rm bar`

Ruby also has a bunch of file operations inside of File and FileUtils.
There's even an Etc object for doing some common operations for things
you normally see in the /etc directory.

Myself and a few others are typically hanging out in the #jruby and
#monkeybars channel on freenode, and we're always willing to give a
hand with these tools. Monkeybars, Rawr, and JRuby all have mailing
lists if you'd prefer to contact us that way as well.
 
P

Phlip

Ruby has methods of making complicated console calls such as system,
sh, and the backtick (`).
Yes!

For example:
system "cd foo"
system "rm bar"

No!

Firstly, the cd can't influence the rm, because they ran in different contexts.

Nextly, only use system when you can't use a raw Ruby call. They are much more
typesafe:

Dir.chdir 'foo' do
Pathname.new('bar').unlink
end
 
V

Vince Angeloni

Ott said:
i am trying to find a good scripting language for Mac OS X. I was told
ruby would be a good choice. Before i dedicate my time to learning it I
have to find out a couple of things.


Can you run ruby frorm the GUI? i.e double click it . I don't want users
to have to go to the terminal.

You can use "Platypus" to wrap ruby and shell scripts in a nice
double clickable wrapper. http://www.sveinbjorn.org/platypus

Keep in mind that if you require a user interface with buttons
and menus, you will need to script all that in ruby using one
of the gui add-ons. Or, if you only require a limited user
interaction, similar to what one could do in applescript, then
you could use rb-appscript to access the
Applescript scripting additions which provide for such interactions.
Here is an example of what i would like to do. We use a package builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

Yes, you could do this with ruby, but also with plain Applescript.
Or a shell script with Platypus wrapper....
I'm not sure ruby provides a big advantage here...

vince
 
K

Kaldrenon

i am trying to find a good scripting language for Mac OS X. I was told
ruby would be a good choice. Before i dedicate my time to learning it I
have to find out a couple of things.

Can you run ruby form the GUI? i.e double click it . I don't want users
to have to go to the terminal.

Here is an example of what i would like to do. We use a package builder
to customize installs. The only part that it can't do is user related
preferences and library files. Which means we(IT department) have to
copy the files. It is easy to do and it only takes about 3mins. But it
would be nice if i could just double click a script and have it take
5sec. Is this something I can do with ruby?

I am more concerned with running it from a GUI. If I can't do that I
might as well stick to shell scripts because I can call them from apple
script which I can run form the GUI. Plus I already know shell
scripting.

I'm not a MacOS user, so I don't know much about this, but does MacOS
X have something equivalent to Windows' batch files? In Windows, you
could make any ruby program double-click executable by making a file
called [program_name.bat] and giving it the line "ruby path
\program_name.rb"
 
U

Une Bévue

Ott Mr said:
Can you run ruby form the GUI? i.e double click it . I don't want users
to have to go to the terminal.

the simplest way is to put an extension od command to your script, it
will be executed on the teminal automagically.

for example :

--- code --------------------------
#!/usr/bin/env ruby
`say hello`
--- /code --------------------------

save it as "say_hello.command" ( may be with x perms, don't remember

and it will open a term and say "hello"...
 
D

David Masover

Dir.chdir 'foo' do
Pathname.new('bar').unlink
end

And this is an example of when a shell script may be more appropriate.

Ruby is great as soon as you need just about any structure at all, but I
wouldn't use it for what would be a one-liner in the shell, except to call
that one-liner in the shell:

system 'cd foo; rm bar'

Or even:

rm 'foo/bar'

It would help if we knew more about what's needed by that script.
 
M

Mohit Sindhwani

Kaldrenon said:
I'm not a MacOS user, so I don't know much about this, but does MacOS
X have something equivalent to Windows' batch files? In Windows, you
could make any ruby program double-click executable by making a file
called [program_name.bat] and giving it the line "ruby path
\program_name.rb"

This is probably one of the few times I've seen someone say "does XYZ
have an equivalent to this Windows ability?" :)

Since I'm still on Windows quite often (due to reasons I don't wish to
detail), it's nice to see :)

Cheers,
Mohit.
12/31/2008 | 12:00 AM.
 
L

Louis-Philippe

very simply,
you need to make your script shell executable.

1 - Put a shebang line as the first line of your script: #!/usr/bin/env rub=
y
2 - make your script executable, with something like 'chmod a+x
/your_file.rb' in the shell
3 - then to make it clickable, change its extension from .rb to .command.

voil=E0!

2008/12/30 Mohit Sindhwani said:
Kaldrenon said:
I'm not a MacOS user, so I don't know much about this, but does MacOS
X have something equivalent to Windows' batch files? In Windows, you
could make any ruby program double-click executable by making a file
called [program_name.bat] and giving it the line "ruby path
\program_name.rb"

This is probably one of the few times I've seen someone say "does XYZ hav= e
an equivalent to this Windows ability?" :)

Since I'm still on Windows quite often (due to reasons I don't wish to
detail), it's nice to see :)

Cheers,
Mohit.
12/31/2008 | 12:00 AM.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top