Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:59:53+00:00 2026-05-25T15:59:53+00:00

In a small backup utility, I’m trying to use system() to write to the

  • 0

In a small backup utility, I’m trying to use system() to write to the user cron table in objective-c.

Now I’m doing this:

NSString *croncmd = [NSString stringWithFormat:@"echo -e 'MAILTO=\"\" \n*/1 * * * * \"%@/Library/Application Support/LBKP/cron/croncall\" %@ > /dev/null 2>&1' | crontab" , NSHomeDirectory(), backup_id ];

system([croncmd UTF8String]);

As you can see, first I simply tried to use > /dev/null 2>&1 to get rid of the mails in case of error… but in OSX seems like it doesn’t work at all and I still get emails.

Then reading some info online I just come across the usage of MAILTO="" at the start of the cron table to discard all the outputs.

The problem is that I need to echo a “new line” to the crontab file witch can usually be made using the -e option and \n char in the terminal, but if I do it from my program I get this in the console:

17/09/11 16:32:52,590 [0x0-0x3a03a].com.home.LBKP: "-":0: bad minute

What’s the problem? :S How can I get rid of this error or just the output?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:59:53+00:00Added an answer on May 25, 2026 at 3:59 pm

    I just discovered that the problem was caused when I added quotes and other things to make the NSString… Anyway I found that the safest way to do this is:

    NSString *disbl_mail = @"echo 'MAILTO=\"\"' | crontab"; // Disable all cron mail...
    system([disbl_mail UTF8String]);
    
    NSString *croncmd = [NSString stringWithFormat:@"(crontab -l; echo '*/1 * * * * \"%@/Library/Application Support/LBKP/cron/croncall\" %@ > /dev/null 2>&1') | crontab -" , NSHomeDirectory(), backup_id ];
    system([croncmd UTF8String]);
    

    The second command syntax (crontab -l; echo lists the available info on the cron table and then echoes it and the new command back to the cron. This way the previous MAILTO="" entry will not be deleted.

    Anyway, and specially because I know this is not the best way to add stuff to the crontab I’m posting a new question here: Obj-C: What is the best way to add jobs to crontab?.

    Hope this can me useful to someone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a small backup script that would take my shelf changes
Backup Script Please check the link above, I wrote this small script in python.
I am working on a small backup application for my personal use, and as
I have a small application which I am going to use to backup and
I am creating a small backup script for my personal use, and it works
Small design question here. I'm trying to develop a calculation app in C#. I
I have a reasonably simple a reasonably system that are conceptually 100,000's of small/simple
I am working on small scale deployment system for our in-house software that manages
I'm working on a small web form that requires the user to input (among
I've been working on this small piece of code that seems trivial but still,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.