0

I am having simple ruby script which will send mail after certain time, this is my code :

#!/usr/bin/env ruby
system("at now + 1 day <<END
echo 'This is test message from xyz' | mail -s 'Test message' [email protected]
END")

whenever I run this script, I get

sh: END: not found

Edit 1

If I use on single line like

system("at now + 1 min echo 'This is test message from xyz' | mail -s 'Test message' [email protected]")

it gives error :

syntax error. Last token seen: e

Garbled time

what am doing wrong in this ?

6
  • what does END command/template do? Commented May 31, 2016 at 11:31
  • @emaillenin I have used it for multiline command for system, If I am doing wrong than what would be the correct syntax for sending mail. ? Commented May 31, 2016 at 11:32
  • does it work if you do the same using a single line? Commented May 31, 2016 at 11:36
  • @emaillenin see my updated question Commented May 31, 2016 at 11:40
  • 1
    syntax error. Last token seen: e This command does not work when run from the terminal. You get the same error. Commented May 31, 2016 at 11:46

1 Answer 1

4

The at one-liner form can be like echo 'COMMAND' | at WHEN.

You can try this:

system("echo \"echo 'This is test message from xyz' | mail -s 'Test message' [email protected]\" | at now + 1 day")
Sign up to request clarification or add additional context in comments.

3 Comments

your suggestion will take me to at> command line which I don't want. I want this script should send the mail
thanks, that's what I wanted. but could you please explain me bit. why have you used double echo ?
@arzyfex only the first echo matters, the second echo is just part of COMMAND.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.