Learning the Mac OS X Terminal: Part 1
Pages: 1, 2
cp
Before you modify the system crontab, you should first make a backup copy in case you need to revert back to its default state. You’ll use the cp, or copy command, to do this, which lets you copy and rename a file in one step. Normally, to rename and copy a file into the same directory, you would type cp, followed by the name of the original file, and then the name of the copy:
[crontab: /private/etc] chris% cp crontab crontab.bak
cp: crontab.bak: Permission denied
But hold on. It looks like you don’t have permission to write to the etc directory. In fact, only root can write to /private/etc. So, because you are not logged in as root, it might seem that there’s no easy way to write to this directory. But there is....
sudo
The sudo utility, for "substitute-user do," allows you to gain temporary root privileges on a per-command basis. To use sudo, simply preface the command you wish to run as root with sudo and a space, and sudo will prompt you for your password (not root’s). If you have administrator privileges, entering your password will run the sudo’ed command as if root were doing it.
Warning: Use sudo with care. You can easily make mistakes with sudo that could require complete re-installation of the OS to get going again. If that thought makes you queasy, it would be wise for now to use sudo only as directed in this article.
To perform the previous command successfully, preface it with sudo:
[office_g4:/private/etc] chris% sudo cp crontab crontab.bak
Password:
[office_g4:/private/etc] chris%
Notes about sudo:
- The first time you run
sudo, you’ll see another reminder to usesudowith care. - You’ll only need to enter your password when you haven’t already used
sudowithin the last 5 minutes. - It’s not necessary to activate the root account to use
sudo.
What you need to do next, then, is edit this system crontab file, and you’ll learn how to do it with a command-line text editor called pico. However, if you were to first examine the privileges for /etc/crontab, you would see that it’s owned by root, and only root has write privileges. Sounds like another job for sudo!
pico
Of the several CLI text editors included with Mac OS X, pico is the easiest to learn. To open a text file in pico, simply enter the file name after the pico command. Used with sudo then, the command to edit the crontab file in the /etc directory looks like this:
[localhost:/private/etc] chris% sudo pico crontab
And this is what you’ll see when you run it:

The document’s text area lies between the black title bar at the top and the two rows of command prompts at the bottom. The Terminal window’s scrollbar won’t let you scroll through the document. Instead, you use the down-arrow to move the cursor down line by line, or use the Page commands.
All of the commands listed at the bottom are prefaced with the caret character ("^"), representing the control key. So for example, to go to the next "page" (actually screen-full) of text, press the control and "V" keys as indicated. For brief descriptions of all the commands, read the pico help file by pressing control-G.
The numbers in the circled area specify the time cron runs the scripts (there are actually three of them), and this is where you’ll make your changes.
Each of the three lines (numbered 1, 2, and 3) specifies one of the three scripts cron runs by default. Each script is different, performing its own appropriate set of maintenance procedures. The "daily" script, specified on the line labeled 1, runs once each day. The "weekly" script, specified on line 2, runs once each week. And the monthly script, specified on line 3, runs -- you guessed it -- once each month.
The first five columns or "fields" of each line specify at exactly what interval the script will run. The fields specify from left to right: minute, hour (on a 24-hour clock), day of the month, month, and weekday (numerically, with Sunday as 7). Asterisks used instead of numbers in these fields mean "every."
For example, line 1 specifies a time of 3:15 a.m.:
15 3 * * * root sh /etc/daily 2>&1 | tee /var$ …
Since the rest of the columns contain asterisks, the daily script (which is written in a file named on that line by its path name /etc/daily) will run at "3:15 a.m. on every day of the month, on every month, and every day of the week," that is "every day at 3:15 a.m."
Line 2 specifies that the weekly script runs at 4:30 a.m. on every weekday number 6, or Saturday:
30 4 * * 6 root sh /etc/weekly 2>&1 | tee /var$ …
And line 3 specifies that the monthly script runs at 5:30 a.m. on day 1 (the first) of each month.
30 5 1 * * root sh /etc/monthly 2>&1 | tee /var$ …
By just changing these numbers, then, you can have these scripts run at more reasonable times. Of course, what’s "reasonable" depends on your own situation, so consider these factors when deciding:
- Choose a time when your Mac is likely to be on (and not asleep).
- Choose a time when a few minutes of background activity won’t disturb your work too much. On faster machines especially, the activity is hardly noticeable, but it could cause some stuttering if, for example, you happened to be watching a DVD at the time.
- Choose a time that is unique for each script. You don’t want to schedule scripts to run at the same time.
For example, these times might be good for a machine that’s only on during normal work hours:
- Daily -- every day at 5:15 p.m.
- Weekly -- every Monday at 8:50 a.m.
- Monthly -- the first of every month at 9:30 a.m.*
*(Of course, the first of the month sometimes falls on a weekend or holiday, but for now, that’s the best you can do. You’ll find a work around to this problem in Part 2 of the article.)
To modify the crontab file to reflect these new times, use the cursor keys (the four arrow keys) to move the cursor to the proper field. Except for being unable to use the mouse, you’ll find that editing text with pico is similar to doing so with any GUI text editor. Use the delete key as usual, and type in the new values.
First, change the 3 in the daily script line to 17:
15 17 * * * root sh /etc/daily 2>&1 | tee /var$ …
Next, change the time in the weekly script line as shown, and the day from 6 to 2 (Saturday to Tuesday).
50 8 * * 2 root sh /etc/weekly 2>&1 | tee /var$ …
Finally, change the time in the monthly script line as shown:
30 9 1 * * root sh /etc/monthly 2>&1 | tee /var$ …
Once you’ve made the changes, save ("write out") the document by pressing control-O. You’ll then be prompted to confirm the save. Just press Return to do so.

Finally, quit pico, by pressing control-X.
Once you’ve saved the crontab file, the new scheduling takes effect; there’s no need to restart. For now, you’ll not receive notification of the completed cron jobs, but in Part 2, you’ll learn how to make that happen, as well as learn more about the scripts themselves.
Chris Stone is a Senior Macintosh Systems Administrator for O'Reilly, coauthor of Mac OS X in a Nutshell and contributing author to Mac OS X: The Missing Manual, which provides over 40 pages about the Mac OS X Terminal.
O'Reilly & Associates recently released (December 2001) Mac OS X: The Missing Manual.
Sample Chapter 2, Organizing Your Stuff, is available free online in PDF format.
You can also look at the Full Description of the book.
-
For more information, or to order the book, click here.
Return to the Mac DevCenter.
Showing messages 1 through 115 of 115.
-
NOPE - I don't get it.
2010-02-28 09:18:33 zeroge [View]
-
NOPE - I don't get it.
2010-03-10 16:14:18 joel1138 [View]
Try the command "locate crontab"
It will list all the files with "crontab" in the title.
-
Sudo code not working "command not found"
2009-08-26 06:47:21 renrut16 [View]
Working in terminal trying to install a program to my mac.
1.) Last login came on. entered code and entered my invisible admi. password
2.) Box opened in TEXT/EDIT program. I then entered a new code and saved. not saved as.
3.) my directions told me to open a new window box in terminal(Or a new shell)
4.)When I entered the new code in terminal it told me "Command not found"
Someone told me when terminal has two windows open it begins to have problems? This true? Is there anyway I can fix the problem?
**Not sure which version of mac I have. Mac OS imac 2006.
-
no such file or directory
2009-05-05 05:35:40 Carson Ramsdell [View]
it says when i try to copy crontab that there is "no such file or directory"
i have a new macbook...thanks for helping
-
Please note: Author's note at top of page 1 about applicable OSes
2008-02-14 15:13:59 lpainter [View]
Author Update, 9/26/2002: The procedures outlined in parts one, two, and three of this series work with Mac OS X versions 10.1 through 10.1.4. The update to part three shows you how to make the procedure work in Mac OS X 10.1.5.
Note that you should not attempt these instructions on OS versions other than those specified by the author.
-
Why do images change to terminal icon?
2007-12-18 12:42:04 Jynja [View]
I am on OSX4 10.4 11
I recently downloaded some pics from my camera disc to my mac. Some were corrupted while others show a terminal icon with the word "exec."
Is there a way to retrieve the original picture?
Is there a way to stop this from happening?
I appreciate any help.
Thanks
Jynja
-
USING TERMINAL FOR MAIL
2007-11-30 11:04:25 elcid07 [View]
I am new at this so forgive me. I am looking to use terminal to read my email. Is this possible and simple? I really want to get behind OS X and use its power. Why not the mail program already loaded? I like the simple look of terminal and the trans function. Okay too much TV/MOVIES with the COOL mail programs.
-
when i do the "sudo pico crontab" thing, it doesn't work
2007-08-30 14:48:29 uber_noob [View]
i took a screenshot but don't know how to post it...
it says:
__________________________________________________
GNU nano 1.2.4 File:crontab
--------------------------------------------------
# The periodiccand atrun jobs have moved to launch jobs
#See /System/Library/LaunchDaemons
#
#minute hour mday month wday who command
-------------------------------------------------
i have absolutly no idea what to do, and im too scared to try anything on my own.
please help me, my e-mail is "b.a.parke@gamil.com"
-
Oasis members really did it!!!
2007-08-08 03:43:37 alexeiw [View]
(http://lincolnschallengeacademy.com/)
-
hello
2007-08-08 03:42:34 alexeiw [View]
http://yo.com
[url]http://yo.com[/url]
-
Today, for the first time in the 25-year history
2007-08-08 03:41:12 alexeiw [View]
BOSTON, MA – OASIS members have approved the Open Document Format for Office
Applications (OpenDocument) v1.0 as an OASIS Standard, a status that signifies
the highest level of ratification. OpenDocument provides a royalty-free, XML-based
file format that covers features required by text, spreadsheets, charts, and
graphical documents. "XML doesn't always mean open. You can hide a lot in
a file format. OpenDocument represents an opportunity to ensure truly open
file formats for productivity applications, which is why it will receive the
enthusiastic support of public sector steering organizations on a global basis,"
commented James Governor, principal analyst at RedMonk. "The participation
of enterprises in vertical industries, such as aerospace, will also ensure
adoption in the private sector. One key to success will be the royalty free
status of the spec; there are no financial penalties associated with deelovping
to it<font color="#666666"> <font color="#000000">acomplia</font> (http://lincolnschallengeacademy.com/) </font><font color="#CCCCCC">
</font><font color="#000000">online</font> (http://lincolnschallengeacademy.com/) ." "Office productivity applications
and the documents they create are key to today's knowledge economy. Information
critical to the long term functioning of any organization is stored in the
spreadsheets, presentations, and text documents its employees create," said
Michael Brauer of Sun Microsystems, chair of the OASIS OpenDocument Technical
Committee. "Today, for the first time in the 25-year history of office applications,
such documents can be stored in an open, standardized, and vendor-independent
format." OpenDocument provides a single XML schema for text, spreadsheets,
charts, and graphical documents. It makes use of existing standards, such
as HTML, SVG, XSL, SMIL, XLink, XForms, MathML, and the Dublin Core, wherever
possible. OpenDocument has been designed as a package concept, enabling it
to be used as a default file format for office applications with no increase
in file size or loss of data integrity.
-
Sudo command...
2007-05-09 20:10:33 DKAMagic [View]
What is a command similar to sudo that can be used in Windows? Sudo works on Terminal but I doubt it will on a Windows command prompt. Thanks.
-
So far, so good
2007-02-12 13:59:54 Harlemite [View]
So far, so good, but, unfortunately, there was nothing in my crontab folder to change for the excercise. I'm going to dare to move on to the next part.
-
Command line for Word
2006-01-27 04:53:10 Charliefarley [View]
This is heresy for long time Mac heads, but I
want to call Word from within my application using a command line. Normally in that other well known operating system, I would type c:\..\program files\..\winword.exe
Can I do that using the OS10 commandline? If not, how can I call word from a script?
Charlie
-
Command line for Word
2006-11-29 09:32:16 tcomputerchip [View]
Just reading through questions, surprised no one gave you an answer.
You can create alias to your programs, but first this is how you open it.
% open -a Microsoft\ Word
now, that seems a bit long, and you need to have the "\" as the application is named that way in the applications folder.
Alternative:
% vim ~/.bash_profile
alias word 'open -a Microsoft\ Word'
alias photoshop 'open -a Adobe\ Photoshop\ CS\ 2'
save that file,
then source it or relaunch your shell
type:
% word
that should do it...
-
sudo pico crontab
2006-01-23 11:05:23 jrodri26 [View]
When i input this command the black bar and control option come on in the top and bottom, but there is nothing underneath the date,week,month line, instead above it says, "the periodic and atrun jobs have moved to launchd jobs .... see /System/Library/LaunchDaemons.
I was wondering if you could let me know where i could go from here to edit the crontab times so that i may continue the tutorial.
Thank You -
sudo pico crontab
2008-10-19 09:44:27 voice18 [View]
When i input this command the black bar and control option come on in the top and bottom, but there is nothing underneath the date,week,month line, instead above it says, "the periodic and atrun jobs have moved to launchd jobs .... see /System/Library/LaunchDaemons.
I was wondering if you could let me know where i could go from here to edit the crontab times so that i may continue the tutorial.
Thank You -
sudo pico crontab
2006-01-23 12:22:35 Chris Stone |
[View]
As mentioned in the notes at the beginning of this article, this tutorial only applies to Mac OS 10.1, so is rather out of date. launchd is an element of 10.4 (TIger), so you'll not be able to follow this tutorial with that machine. For Tiger users, there's an excellent new series of articles by Mary Norbury-Glaser beginning here:
http://www.macdevcenter.com/pub/a/mac/2005/05/20/terminal1.html
--Chris
-
Perl Scripts
2006-01-09 14:38:01 Cruzapete [View]
I dont know if this is too late that it wont be answered. I will so much appreciate it if it can be treated and my problem solved.
I was a windows user but moved to Mac OS X. I have some perl scripts I run on MS-DOS cmd.exe but have been having problems running those scripts on Mac OS X terminal.
Is there any command used for running perl scripts or how do I go about it.
Thanks for responding.
Cruzapete -
Perl Scripts
2006-11-29 09:39:26 tcomputerchip [View]
you are probably using hard coded things that wont work on the mac. Things like "C:\windows\notepad.exe" would not work on OSX, but more specific you may have a problem with the slashes and carriage returns. When comming from windows, text files have a CT LF (Ctrl+Line Feed) OSX uses many forms of this, if you open the file with vi or pico, you would see something like ^M (this means that the OS can't read the meta character in that location, but the meta character is still in the file.) You can do a simple perl script on the Mac that searches for the meta character and replaces it with the proper "OSX" carriage returns.
-
Process cron stealing a lot of cpu time
2005-11-15 10:31:58 Vilhs [View]
Hi there!
In my university i have a signature of Administration of Operative Systems and i've started to study the cron.
It happens that i made my little experiente on my PB and i didn't turned out very well.
I've edited the crontab file like this: */0.5 * * * * echo ola
And i saved it. Nothing happened! Then i erased the crontab file eith the command cront tab -r.
Few days later i realized that my battery life was strangely running out in a very fast way. I looked at the activity monitor and there was the cron process running and consuming a lot of cpu time. I tryed to kill, wich actually happened,but you know, the cron actualizes every 1 minute, so i can't get him out of my process list.
What can i do?(besides lowering the process priority)
Thank you for the attention! Greetings!
-
How do I manage different hard drives?
2004-10-26 12:26:29 Cissi [View]
I have added an external hard drive to my laptop, and so have two discs. In the graphical interface that is simple to handle, but I usually use the terminal for managing my files? The question now is how do I get into the file system of my external hard drive? -
How do I manage different hard drives?
2005-10-14 10:20:53 js2000 [View]
try
$ ls /Volumes
or with this switch
$ ls -l /Volumes
for exploring additional other drives
-
Mail in OS X Terminal?
2004-05-01 18:47:20 surfs [View]
I launched my Terminal and I get this:
Last login: Fri Apr 30 23:11:53 on console
Welcome to Darwin!
You have new mail.
It says I have new mail - but how do I check it with the terminal? I tried using the mail.app, but nothing. Anyone know how?
Thanks in advance! -
Mail in OS X Terminal?
2004-05-02 15:54:12 lpb2h [View]
At the command line, type:
/usr/bin/mail
That runs the mail client on your system. Long before http, this is how many UNIX people read mail.
See "man mail" for details.
If when you type "which mail" you get "/usr/bin/mail" then you can just type "mail" to read mail.
-
I feel like a techy already
2004-03-31 03:46:47 10n6 [View]
Great lunchtime learning. neve new about pico before. Well I never really used the terminal except for ftp before. Thanks for this. I'm continuing on to see how far I get before my head blows up.
-
sudo pico crontab
2003-08-19 21:35:30 anonymous2 [View]
When I enter "sudo pico crontab" it shows nothing....What am I doing wrong?
trentalan@yahoo.com
-
Toad
2003-08-09 15:35:12 anonymous2 [View]
Wow, that cetainly rekindled my already flameing love affair with my mac.
-
coachferrigan
2003-07-09 14:04:56 anonymous2 [View]
Trying to enable PHP via the following commands but will not start. Cked and recked my typing but still will not start. Any ideas?
cd /etc/httpd
sudo apxs -e -a -n php4 libexec/httpd/libphp4.so
sudo perl -p -i.bak -e 's%#(addtype \S+-php[ -]%$%i' httpd.conf
then to restart apache
sudo apachectl graceful
-
WriteOut?
2003-07-06 00:52:12 anonymous2 [View]
After I make the changes of the crontab scheduling in pico and command+O to WriteOut, a screen appears that says "Open" and allows me to browse my files. It says in your article that WriteOut is used to save the changes. What am I doing wrong?
-
Connecting to a remote server?
2003-06-25 17:00:35 anonymous2 [View]
How do I connect to a remote server using the Terminal? LIke www.yourdomain.com? -
Connecting to a remote server?
2004-01-13 12:10:01 anonymous2 [View]
telnet www.yourdomain.com
You obviously need a login id and password, though...
-
pico error
2003-06-11 22:48:24 anonymous2 [View]
I get an error when i try to run "sudo pico crontab"
error: Unknown terminal type network!
any help?
oh, when I run it from File>New Command it opens the Pico editor, but it doesn't load the crontab file.
-
Learned alot
2003-03-16 11:47:06 buz [View]
Thank you - is part 2 coming.
-
cd and directory names
2003-03-11 19:20:03 anonymous2 [View]
Hello:
OS 10.2.3
First time Terminal user.
The ls and pwd commands work but I'm having trouble with cd.
In my Users folder there's the standard Pictures folder.
In that folder I created a folder /directory called General Pictures.
I can use the cd command to get to Pictures but when I'm at
[localhost:/] myname%
I type
cd /Pictures/General Pictures
and I get back
cd: Too many arguments
I've tried a number of ways of writing the command but I've been unable to get to the general Pictures folder from within Terminal
What am I missing?
Thanks
-
cd and directory names
2004-03-27 20:47:22 rcrow [View]
try cd /pictures/General\ Pictures -
its easy
2003-03-12 07:36:38 anonymous2 [View]
you need to type
cd ~/Pictures/General Pictures
or
/Users/<username>/Pictures/General Pictures
since your Pictures Folder is not in the root-directory but in your home directory
- tell me if it worked - -
its easy
2003-03-12 09:26:20 Chris Stone |
[View]
Well, you're halfway there...:-)
First, what you were attempting to cd to was a directory called "Pictures Folder" at the very top of your directory tree, i.e., "root". You were specifying this by beginning the pathname with a "/", which indicates the absolute pathname.
However, if you are already in your home directory and want to go down a level to, say, Pictures, then you would use a relative pathname, that is one that does not begin with the "/".
There is still a second issue, however, which is resulting in your "cd: Too many arguments" error. Remember that the shell sees the space character as the separator of arguments. So when you have a pathname containing a space, as in your case, cd breaks that string of text at the space and tries to handle the two strings as separate arguments instead of as a single one. cd won't work with multiple arguments, however, so you get the error.
The fix? Well, what you need to do is indicate that the space is not an argument separator, but the literal space character. The two ways to indicate that, or "escape" that character, are by either preceding it with a backslash, or enclosing the argument in quotes.
For example, either of these two commands would do what you need, with your working directory being your home directory:
cd Pictures/General\ Pictures
cd "Pictures/General Pictures"
BTW, a cool Terminal trick that can save some time is to just drag the actual folder icon of the directory in question from the Finder desktop right into the Terminal window (after you've typed cd and space, for example), and the fully escaped pathname will get entered right into the command line for you.
Hope that helps!
--Chris -
its easy - and thanks
2003-03-13 05:20:15 macmartin [View]
of course you are right -
I could have figured this out if I had done this on the Terminal
thanks for the great article - it helped me a lot
greetings from germany
-
New User Account!?!?!!?
2003-03-05 18:13:57 anonymous2 [View]
I need to create a user account in the terminal. My home folder was deleted while in the Mac os 9 startup disk. Then the G3 was rebooted into the startup disk mac os x and now I'm stuck there with nothing to do. I have no sys prefs either. I'm stuck and have no one that can help me. Please help me. Thank you
Email me at laulaunpoi@aol.com Thank you
-
New User Account!?!?!!?
2003-03-05 18:12:50 anonymous2 [View]
I need to create a user account in the terminal. My home folder was deleted while in the Mac os 9 startup disk. Then the G3 was rebooted into the startup disk mac os x and now I'm stuck there with nothing to do. I have no sys prefs either. I'm stuck and have no one that can help me. Please help me. Thank you
-
UNIX CLI
2003-02-24 09:21:56 anonymous2 [View]
hit there.
just brushing-up on my MAC Unix commands.
Read the first tut and it seems to be pretty simple.
Having worked at an ISP before, the PC Unix CLI was a common thing, but then that was about 6 years ago and I've forgotten most of it. For email I use PINE just beacause it's simple and for text based website, Lynx.
Looking forward to learning more.
Best,
Andrew WInter
abw@sentex.net
-
CronniX
2003-02-08 17:50:21 anonymous2 [View]
Looks like you can also modify the cron jobs with this app called CronniX. I haven't tried myself yet, but I'm wondering if there's any differerence.... Has anyone tried this? - http://www.apple.com/downloads/macosx/unix_open_source/cronnix.html
-
Trying the command line for the first time
2003-01-20 13:46:58 anonymous2 [View]
Had experience with MS-DOS. So navigating goes well, because this is similar, but that might be because DOS was a bad copy of the Unix CLI. (So i heard.)
-
Can't enter my password!
2003-01-16 19:25:28 anonymous2 [View]
Everything is fine sudo prompt me for my password .... but I can't type the password.
Seems like my keyboard is inactive. I'm stuck... :-(
JL
-
Can't enter my password!
2003-01-17 08:47:30 Chris Stone |
[View]
When typing a password for sudo, nothing will appear at the prompt for security reasons, but your keystrokes will still be seen by sudo once you press the final return.
--Chris -
Can't enter my password!
2003-01-18 16:00:50 pixm [View]
Thanks
JL
-
Annoying Programs
2002-12-17 08:40:07 anonymous2 [View]
There is a program that is programed not to quit that one of my friends put on my computer.. Does anyone know the Command Line to quit a program that is stuck in my startup Items that I cannot remove? -
Annoying Programs
2003-11-19 16:06:48 anonymous2 [View]
Try using the "top" command. Type "top" then a long list will appear. Open a new inspector and type "kill <program name>
-
Suggestions for a Jaguar User who has erred?
2002-10-21 09:27:46 bebo [View]
God forgive help me, for I have skimmed!
Seduced by the headlines (and their lackies, the sub-heads) I rushed headlong into Lesson One. Too late I discovered, this was not intended for early adopters like me.
So what's an overly eager boy to do?
Although everything seemed to work as described, I'm now the proud owner of a modified "crontab" (or am I, really?) and am unsure what to do next!
Should I delete it, and rename "crontab.bak" as plain old "crontab"? And if so, how?
Perhaps Lesson Two would answer all, but I'm afraid to proceed - give the fact that it's unsupported under Jaguar.
Suggestions?
-
Very Interesting...
2002-09-06 21:45:16 zeta74 [View]
I am just learning about the Terminal and Mac OS ....this is the most interesting OS-OS X...I am still a beginner althou I had experience working with the Unix once upon a time as a university course. But that was on a windows OS...I am lately working on a friend's iBook and was able to make myself the superuser...but I am stuck wondering how can I give others authority to be super users too?? -
Very Interesting...
2002-09-30 08:53:34 anonymous2 [View]
You edit the /etc/sudoers file. type 'man sudo' for more info.
-
/private/etc/crontab in Jaguar
2002-09-02 20:05:38 mike_dowe [View]
Looks like crontab doesn't sent an output email to root anymore in the new version.
-
cron jobs
2002-08-15 19:49:03 monica1 [View]
nice article, everything worked fine for me.
But: does anybody know, what these cron jobs are doing? -
cron jobs
2002-09-30 08:59:02 anonymous2 [View]
They delete junk files, rotate log files, update needed databases and the like. You can look at the scripts in the /private/etc/periodic directory to see exactly what they do.
-
problems with sudo????
2002-08-08 02:52:52 rlois [View]
i am having problems with sudo. it tells me each time i use it that
sudo: /var/run/sudo owned by uid 501, should be owned by root
what does this mean and how could this have happened?????????//
how do i make sudo owned by root???????????
help -
problems with sudo????
2003-06-01 07:38:33 anonymous2 [View]
well, assuming it works the same as linux you would do on the command line as root
chown root:root /var/run/sudo -
problems with sudo????
2003-02-13 04:45:58 anonymous2 [View]
You've probably solved this problem by now but for those that have not after coming across this page via googling uis 501 should be 0, this is how I fixed it.
Hopefully you have administrative priveliges on your machine, and found the apple developement site not very useful in your plight, open your applications folder, then utilities, open Netinfo manager, click the little lock on the bottom, enter password, click user, then root. click the security tab at the top of your screen, to enable root user, since os x.2 ships with root login disabled you can set the password there. Now log out then log in as root, supply the password you just created. Open a terminal, you know where it is since you used it to hose your sudoers file in the first place. pico /etc/sudoers clear the file then ctrl o the ctrl x the hell out of there. you need to 'chown root /etc/sudoers' then 'chgrp wheel /etc/sudoers. that should fix it. Now go back after you log in under your user name and set the netinfo manager back to disable root login, you don't deserve it.
-
Different PICO output?
2002-08-07 18:24:42 mepasha [View]
In your article you state that the daily script should read like:
15 3 * * * root sh /etc/daily 2>&1 | tee /var$ …
In my terminal it reads:
15 3 * * * root periodic daily
Any ideas on why this is different?
Great article!
pk
aka: another newbie UNIX admin thanks to OS X ;-) -
Different PICO output addition:
2002-08-07 18:27:47 mepasha [View]
There are other significant differences in the Pico output, most notably all of the header info, but I've also noticed that you were running Pico 2.3, and on my machine I have Pico 2.5. Maybe this is the answer, but I would love to hear why these changes would have been implemented.
Thanks again
pk
-
Pico ?
2002-07-09 02:52:11 phil_roy [View]
Hi all,
When I get up to the part on the second page that asks me to type....
sudo pico crontab
I get an error that says....
Incomplete termcap entry
I can't see the Pico app anywhere either? Running OS X 10.1.5
Phil
-
Pico ?
2003-07-20 23:41:32 anonymous2 [View]
"Incomplete termcap entry" is referring to your TERM (terminal) shell environmental variable - which if your box was screwed up like mine had a line that said "TERM=network" or something like that. This won't let you use pico among other annoying things.
To check this simply type "env" at the prompt and all your environmental variables will be listed. A resonable choice for your TERM would be vt100 - which you can set (Assuming you are running tcsh - the default Mac OS X shell) by typing:
[xyz]zyx% setenv TERM vt100
You will probably also want to add the line above to your "~/.tcshrc" file (make that file it if doesn't exist).
To see where the pico application is type:
[xyz]zyx% which pico
And you should see something like "/usr/bin/pico"
If you still can't use pico - check that "/usr/bin" is part of your PATH environmental variable...
Hope that helps. My appologies if you are a solid *nix person and I was talking down to you. It's just that sometimes the OS X users are a bit befuddled by the command line...
-
Terminal to finder and back
2002-06-02 20:53:37 michal.young [View]
It's grand to have both the finder and terminal interface ... but a little clumsy jumping between them. For example, if I am locally editing a web site with Dreamweaver, and posting it through CVS, then I need to be moving back and forth between a finder view and a terminal "view" of the same directory.
To get from terminal to an application, the "open" command is great ... in particular, to open a finder window from a terminal window, and focus it on the current working directory, type
open -a finder .
(that's a dot, aka full-stop, at the end of the command).
But here's a puzzle I haven't solved: How can I do the vice versa jump, from finder to terminal? If I've got a finder window open on a folder, how do I launch a terminal *on that directory.* It's silly and a waste of time to figure out the path and type it in after opening the terminal window. -
Terminal to finder and back
2010-08-15 03:35:53 pklaus [View]
OK, the thread is old but I recently moved to Mac OS X and found this site using a google search so I think I should contribute my findings:
To jump from Terminal.app to the finder:
open .
To jump from Finder to Terminal:
Have a look at the open source tool >cd to... found on http://code.google.com/p/cdto/
I found this approach at http://stackoverflow.com/questions/420456/open-terminal-here-in-mac-os-finder -
Terminal to finder and back
2002-07-03 07:51:15 gasoline [View]
I don't know how to open it directly, but one can drag a particular folder onto the terminal window and it will cd to that directory.
-
/etc vs. /private/etc?
2002-04-02 10:40:29 lorenrf [View]
Great articles, but I was unclear on one thing. What's the difference between /etc & /private/etc?
Thanks,
Loren -
/etc vs. /private/etc?
2002-04-04 10:19:39 Chris Stone |
[View]
Good question...
/etc is actually a symbolic link, (similar to a Mac alias) to the actual directory /private/etc.
You can see this with the ls -l command on the root directory, and looking at the line for /etc:
[localhost:~] chris% ls -l /
lrwxrwxr-t 1 root admin 11 Apr 3 04:44 etc -> private/etc
The first "l" in the line signifies a link. And the reference of that link follows the arrow at the end of the line.
Apple has done this with /etc and a few other directories normally found in the root directory of other Unix systems to provide compatiblity with OS X's own layout of /private/etc. Why does Apple use /private? Well, that's another story, but it started with NeXT.
Thanks,
--Chris -
/etc vs. /private/etc?
2008-01-22 02:05:44 frank143 [View]
Actually how is going in working with MAC
-
Error
2002-03-14 04:19:10 sevenov9 [View]
I get this message right after I push return from "File Name to write : crontab"
"Can not open file for writing". I made a backup copy of crontab and followed your instructions to the best of my ability. What am I doing wrong? And also, my user name is the root's sn. So why did I need to use "sudo" for making a copy of crontab?
-
Even nitpickier
2002-03-13 12:12:02 socokid [View]
First of all. THANK YOU. This was a well thought out beginners tutorial. It helped me quite a bit.
I merely wanted to point out that in your instruction, you stated that we were going to set the weekly time to Monday at 8:50, and yet in the code, you switch to Tuesday. It took me a minute to figure that one out. I went back to make sure you said that 6 was Satruday, making 7 Sunday, and therefore Monday should be 1, but I saw you using 2, and it temporarily made my brain freeze. You simply switched days in the middle of the instruction, no big deal, but it was the only inconsistancy, and it made me stop in my tracks, which were well oiled due to outstanding instruction otherwise.
So, no big deal, just wanted to point it out, and again. THANK YOU.
socokid
-
Initial Prompt
2002-03-05 12:37:50 mgoins11 [View]
My command line prompt reads tcsh_initdir: Undefined variable. Instead of Local Host. Does anyone know how I can remedy this? -
Initial Prompt
2003-06-03 05:19:23 anonymous2 [View]
What works for me is to add the line
source /usr/share/tcsh/examples/rc
at the top of the /usr/share/tcsh/examples/login file.
-
Being Careful
2002-03-01 14:05:20 kwidholm [View]
I've been using the command line for quite a while, and consider myself an intermediate UNIX user, but that doesn't mean I'm immune to carelessness. While I've finally genetically modified my brain to NEVER use asterisk in combination with the "rm" command, there was one command I performed absent-mindedly last week that wreaked havoc, and that I had never thought about as possibly being as destructive as it was. Can I warn you all about it?
I was working on a networking consultancy gig when I noticed sendmail was acting up because the root directory had become group writable again. So I reached over to quickly fix it, and typed:
> sudo chmod 700 /
I should have typed chmod 750, but I didn't. Now, you long time UNIX users will immediately see the horror of what I'd done, but I didn't get it, at least until all sorts of processes began shutting down. Then, it dawned on me: I had basically locked myself out of doing anything.... anything at all on my computer! Nowhere in any CLI tutorials had I been warned of this, and it seemed so innocuous. I wasn't "removing" anything, just reconfiguring. The trouble is, that I couldn't use the sudo command to undo the damage because sudo is a program located in the /sbin directory, and I could no longer access the /sbin directory because I was locked out from any directory past root... i.e., the entire machine.
There may have been some expert way to get out of this, but I sure couldn't think of any. (And I would love to see them listed here). So I restarted from an OS 9 CD, copied all the configuration and User files I could from my machine, reformatted my drive (might as well), and started over.
That's my warning. BE CAREFUL OUT THERE!. Never type sudo with anything less than FULL attention.
KLKTRK -
Being Careful
2003-11-02 00:14:29 anonymous2 [View]
i did almost the same thing,..To fix your problem, if you have a jaguar boot disk, insert it and boot up from it. Go to disk utility and there should be a fix disk permissions option. click it and about an hour and a half later the majority of your problems should be over. Disk utility will reset all the main system file permissions back to normal.
Unfortunatly, i figured this out too late and lost all my stuff that wasnt backed up.
-
Macs & OS X: A beautiful combo
2002-02-10 16:37:05 dasper [View]
I've worked on various platforms, including MVS, VM/CMS, HP-UX, AIX, OS/2 and Windows. In recent years I've become a fan of Open Source as an alternative to Wintel. For me, the new Macs running OS X have been a revelation. I am extremely happy with my new iBook and sincerely hope that Apple keeps OS X as open and close to FreeBSD as possible.
-
Do cron jobs run even if Mac is sleeping?
2002-01-31 10:22:00 nolanl [View]
This is a simple question, but in OS X 10.1.2 when the Mac is in sleep mode will cron jobs run at their scheduled times? -
Do cron jobs run even if Mac is sleeping?
2003-05-14 09:56:17 anonymous2 [View]
Is there a way to get a cron job running on OS 9? I have a perl script I want to run every night at midnight on a load of Mac 0S 9's...
Cheers. (Sorry if this is off topic, it not being about OSX etc.) -
Do cron jobs run even if Mac is sleeping?
2002-02-20 16:37:21 Chris Stone |
[View]
And now the slightly more complex answer.... :-)
Yes, they do, but only with some machines, it looks like. It doesn't work for me on a Lombard, but does on a Gigabit G4.
--Chris -
Do cron jobs run even if Mac is sleeping?
2002-02-01 12:17:26 Chris Stone |
[View]
And a simple answer... :-)
No, they won't.
--Chris
-
Groups: wheel and staff
2002-01-29 12:17:53 pattyb777 [View]
I executed the command 'groups' and it showed me three groups: staff, wheel, and one other that I can't remember. Who are these groups and what is their purpose?
Thanks, pattyb -
Groups: wheel and staff
2002-02-07 05:26:52 xa40d [View]
the groups command lists the groups you are in. Groups allow you access various parts of the filesystem do an `ls -la' to see a list of all the files in a directory, including the file permissions and ownership. Groups also allow you access to advanced funtions of some commands. For example being a member of wheel allows you to `su' to root, i.e. to become the super-user
-
Part II please!
2002-01-16 11:02:21 tripphome [View]
Thanks for getting me moving in the right direction. I've got the Missing Manual on order from my local bookstore and going crazy waiting for part II of this great article.
I'm a recent convert from PC side to MAC and I really appreciate the O'Reilly Network opening up about Mac with OS X.
thanks -
Part II please!
2002-01-17 11:07:37 Chris Stone |
[View]
Glad you enjoyed Part 1!. Part 2 is "in the can" and will be posted no later than 1/25, so please stay tuned...
--Chris -
Part II please!
2002-03-13 12:15:05 socokid [View]
It's 3/12.
Not complaining, just wanting to continue. This stuff is GREAT. -
Part II please!
2002-03-13 12:19:39 socokid [View]
Sorry, found part II, and it came out as promised, before 1/25.
Just thought intuitively that there would have been a link at the end of Part I leading to Part II.
Oh well...
-
/etc/hosts Not Used?
2002-01-02 19:12:59 ellem [View]
I wanted to enter a hosts entry like so:
$sudo emacs /etc/hosts
And I amended the hosts file (without read all that "stuff" at the top.)
Upon returning to the hosts file via more /etc/hosts I read all that "stuff -- NUTSHELL Version:
We only use /etc/hosts in single user mode, now we use NetInfo and failing that we use lookupd.
So first the *nix in me went looking for lookupd and the best I could come up with was retart-lookupd. Undeterred I tried to make my entry there. Seeing that that was not the file I was looking for (move aong) I tried to find my entry point in NetInfo. My 3rd 404 in an hour.
Shouldn't this sort of thing be moderately easy? I just want to be able to type a word instread of a number. -
/etc/hosts Not Used?
2002-01-04 13:23:05 Chris Stone |
[View]
Yes, OS X looks at its NetInfo database instead of in /etc for this and other info.
The easiest way to get at NetInfo is with the NetInfo Manager GUI app found in /Applications/Utilities.
Use it to add a host by adding a new record to the "machines" directory. Follow the entry for "localhost" as a guide.
-
behavior of cc in OS X terminal window
2001-12-21 17:03:42 pistor [View]
I have a question regarding the c compiler. When I write a c program hello.c and compile it like this
[localhost:~] myname% cc hello.c
I find the executable file called a.out in the same directory. When I try to run a.out by typing:
[localhost:~] myname% cc hello.c
I receive the following message:
a.out: Command not found.
when I go a directory level up by typing:
[localhost:~] myname% cd ..
and call the program then by typing:
[localhost:~] myname% directoryname/a.out
the program executes correctly. Is this how the terminal is supposed to act and why is this. Why can't a command be found when I am in the same directory as the executable file?
thanks for any suggestions
christoph
-
behavior of cc in OS X terminal window
2001-12-21 20:24:42 hokanstenholm [View]
To run a.out (or any other executable loacted in the same folder) you must write either ./a.out, ("." referes to the current directory) or you will have to add (or create) a "." to your PATH variable in ~/.tshrc, ~/.cshrc ... (~ = home dir, see do man on tcsh, csh ...).
The PATH variable includes all directory paths the will be used to look for a executable called a.out if you do "% a.out" but the "." directory isn't included by default.
-
crontab -e
2001-12-21 09:54:12 sharumpe [View]
This is probably another small issue, but I think it is probably safer to use "crontab -e" to edit your crontab than to actually edit the crontab file.
In most Unix systems I've used, there is a comment at the top of the crontab file that expressly says not to edit that file.
Anyhow, the process to do so is this:
prompt% setenv EDITOR "pico -w" (if you want pico)
prompt% sudo crontab -e
-
crontab -e
2003-03-10 16:03:06 anonymous2 [View]
Any idea on how to have pico invoked as the default editor for OS X Terminal with the -w switch (so it won't mangle wrapped text); i.e., what should be placed in the .cshrc file?
% setenv EDITOR "pico -w"
... works at the command line (well, the OS doesn't complain anyway), but when placed in .cshrc, (and after .cshrc is sourced) I get:
% crontab -e
crontab: pico -w: No such file or directory
crontab: "pico -w" exited with status 1
I'm told that on a Red Hat system it works in the .cshrc file, but in Gentoo Linux (and Mac OS X), it gives the errors above. All three Unix systems use Vixie cron. I also tried:
setenv EDITOR "/usr/bin/pico" -w
... but that doesn't parse:
setenv: Too many arguments. -
crontab -e
2003-07-15 11:10:50 anonymous2 [View]
You can acutally do this by creating a shell script. I had the same problem with the BBEdit command line utility. It took a -w option also. So I created a shell script that look like:
#!/bin/sh
bbedit -w $1 $2 $3 $4 $5 $6 $7
That fixed it! You could probably exchange bbedit for pico and have the same results. -
crontab -e
2001-12-21 10:52:44 jope [View]
That only applies to user crontabs, I think. The article is talking about the system crontab files, the format for which include the user as which to run each job. -
crontab -e
2001-12-21 11:48:47 Chris Stone |
[View]
Right, thanks for clarifying that, jope. Though readers just starting out with the CLI, shouldn't do anything to the system crontab other than what's specified in the article. Editing the user crontabs might be covered in future articles.
-Chris
-
"pico -w" for editing config files
2001-12-21 07:42:20 Jerry Peek |
[View]
When I've edited a crontab with pico on a Unix system, I've found that pico can break long entries (entries that have more than 80 characters, which is the "standard" window width) onto multiple lines. That's a problem because each crontab entry must be on exactly one line; cron won't recognize an entry on multiple lines. In other words, an entry cannot contain a newline character because the cron utility treats each line as a separate entry. (This is a common problem on other Unix systems. Maybe this is different under OS X. I don't have a system handy to check.)
Anyway, the way to keep pico from breaking entries onto multiple lines is to use its "-w" option on the command line. That is:
[host:/etc/private] jerry% sudo pico -w crontab
The screenshots in your article seem to show pico using its "-w" option. That's because the lines you show end suddenly with a "$" character, which is pico's way of saying "there's more off the edge that you can't see". So maybe "-w" is the default under OS X? (Again, sorry, no Mac here.) Even if it is the default under OS X, it *isn't* under other Unix versions... so watch out when you use Pico to edit configuration files and be sure you use "-w".
Jerry Peek -
"pico -w" for editing config files
2001-12-21 09:07:21 Chris Stone |
[View]
Hi Jerry! Thanks for the comment.
As you suspected, pico on OS X *does* open with the -w option by default. So there's no danger of splitting crontab lines by following this procedure.
This does point out the fact, though, that the tutorial is specific to Mac OS X, and should not be tried with other Unices unless you know what you're doing -- in which case, you wouldn't be using the tutorial anyway :-)
Thanks again!
--Chris
-
excellent article, small typo
2001-12-20 15:20:58 sootmann [View]
In the 'pwd' example, you show the directory path (output) on the same line as the command, when it would actually be between the two prompts. otherwise, great article.
-
PWD
2001-12-20 15:07:48 altp [View]
pwd != "print working directory"
Its "Present Working Directory". Its a very common mistake that i see all over the place. Unless its meaning has changed, I learned it from some of the older SCO manuals. Redhat linux in a nutshell also has it as "Present" instead of "Print", if your looking for a more modern reference ;-)
Altp. -
PWD
2001-12-20 17:56:53 Chris Stone |
[View]
Actually, as a command name pwd *does* stand for "print working directory." The common mistake is between this and the variable name PWD, which stands for "present working directory."
Thanks,
--Chris
-
anacron?
2001-12-19 10:15:03 jope [View]
Given that OSX laptops out there, I'm surprised that anacron isn't being used instead. -
anacron?
2001-12-21 11:02:57 jope [View]
Okay, I kinda munged the original question (and nobody's responding) so let me rephrase:
Rather than try to guess at a specific time when your machine is likely to be running, so that your cron jobs get run, there's a more robust alternative: anacron (http://anacron.sf.net) will make sure jobs get run at some point during the day. It's standard-issue for laptop users, of which Mac OS X has many. A quick search on both Google and Apple Support turned up only one stray comment in a review. -
anacron?
2001-12-21 14:42:39 Chris Stone |
[View]
Thanks jope...yep anacron would solve the problem well. Perhaps Apple doesn't include it for licensing reasons. But it is available for OS X by using the fink package installer:
http://sourceforge.net/projects/fink/
-
Mac-like editing
2001-12-18 09:50:45 canyonrat [View]
Pico is OK, I guess, but as a real Mac baby I've found that if the job isn't heavyweight enough for emacs then it's easier to just type:
open -e <filename> and edit with TextEdit. This is especially nice if you want to make a small change at the end of a long file because you can use the scrollbars to get where you want quickly. -
Mac-like editing
2001-12-18 10:33:41 Chris Stone |
[View]
Yes, open -e is a great command, which I'll explain further in Part 2. However, if you've applied Apple's security update already , open will no longer correctly work with sudo. That it, it will no longer let you edit the file and save it as root.
One workaround to this, however, is to run the actual TextEdit executable from the CLI like this:
%sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/crontab
Thanks for the comment!
--Chris -
Mac-like editing
2002-01-27 06:23:01 dusterella [View]
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/crontab
works for me -- opens up crontab in textedit -- but then the terminal window cursor just sits there -- no % prompt -- and i can't return to % to use terminal window for anything else.
Isn't there an easier way do to this? I had a much easier time doing this sort of thing on a remote linux box just ftping files and editing w/ bbedit.
On the plus side, I've found that once I've openned a file with sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/crontab, I can then use TextEdit to direcly edit and save httpconf, crontab files and the like. But then I have to quit and relaunch Terminal to get back the % prompt.
-
Mac-like editing
2002-02-11 11:51:06 itgs__ [View]
Well I haven't actually ever used Mac Os X as of yet, though I have a Mac, but from what I know about the CLI, all you have to put at the end of the command in order that you can continue using the prompt is a & (and symbol). You use this a lot in Linux when you are in certain environments and you want to open an application but at the same time be able to use the shell..
Good day :>) -
Mac-like editing
2001-12-18 13:00:50 pmccann [View]
One of the thoroughly nice aspects of BBEdit 6.5 is that it does allow you to simply edit system files via the
% bbedit /etc/crontab
syntax. You get a gentle jab "file owned by root: unlock?" when you first attempt to edit the file (but only if you don't have write permission). Unlike, vi or pico, where you can make all the editing changes, try to save, and then finally realise that you forgot to "sudo" at the start. Back out, back in, do it all again. On saving the file in BBEdit you're prompted for an admin password, a la sudo. A thoroughly suave implementation.
Of course pico's about as gentle as a cli editor gets, so good choice given the subject of the article!
Happy user, no other affiliation, rah rah...
Paul
-
A little nitpick
2001-12-18 06:16:46 pmccann [View]
Namely: the s in "sudo" is for *substitute* user, not *super*. You can just as well use sudo to run a command as any user (ie not just as root) by employing the -u flag on the command line.
For example, user "wilma" might enter:
sudo -u fred kill -9 1234
If wilma has been granted sufficient "power" in the /etc/sudoers file she'll be able to kill off Fred's CPU hogging processes using variants of the above command. As Apple have configured things out of the box, doing so would require Wilma to be an "administrator": all administrators have full sudo access, and no other users have any access via sudo. But you *can* set things up (very easily) so that the above command is the *only* rootly thing that Wilma can do. In summary, Wilma can substitute herself for Fred (only), to do (only certain things).
Cheers,
Paul -
A little nitpick
2001-12-18 09:09:35 Chris Stone |
[View]
Thanks Paul -- sorry to have let that one slip by! As you point out, there is a lot more to sudo than just using it to gain temporary root privileges. Folks ready for that can get some clues from the sudo man page via:
%man sudo
and
%man sudoers
--Chris -
A little nitpick
2001-12-18 12:35:52 Chris Stone |
[View]
In any case, this has been fixed in the article.
--Chris
-
Difference between OS X crontab and Unix crontab
2001-12-17 15:57:44 drew_in_japan [View]
Chris,
I've been using OS X for about two months. I also now have to increase my Unix knowledge since my company just got a HP Unix server. In editing the crontab you mentioned that " (numerically, with Sunday as 7)". In O'REILLY'S UNIX IN A NUTSHELL it lists the day values as 0-6 with 0= Sunday. Is this different with OS X? Or is this what I do sometimes and forget that in computers, 0 does have a place of importance.
Drew -
Difference between OS X crontab and Unix crontab
2001-12-17 18:00:13 Chris Stone |
[View]
Hi Drew,
Thanks for reading the article. Actually you can use either 0 or 7 for Sunday in the crontabs.
For more on this you can read the crontab(5) manpage with:
%man 5 crontab
--Chris -
Difference between OS X crontab and Unix crontab
2003-12-02 22:07:56 anonymous2 [View]
I tried to read this man page but...
[d216-232-220-183:~] kdvolder% man 5 crontab
No entry for crontab in section 5 of the manual
Are the man pages not installed by default? I get the other manpage (section 1) but that only explains the crontab command, not the crontab file format.
Id thid just problem with my setup? I don't think I changed anything.










- but, new to UNIX and OSx, I didn't grasp it, sorry.
I tried to follow the instructions but neither do the commands show what you said it should, nor did a "Spotlight" search show any such file as the "crontab" ... it appears not to exist at all.
I went through the entire OSx directory manually, with the ambition to locate it, but nope - it's not there.
I even tried to find it by toggling hidden files to be shown but still, I can't find it.
So is the same with other files that you listed in your extract and by running the "ls" command.
What is it that I am missing here?
I have 10.6.2 Snow Leopard on IMac
Thanks