4 Nothing here is specific to bash; other shells have here-docs
| link
3 deleted 7 characters in body
source | link

Is it possible to print to crontab with an heredocument?

I tried these but failed:

cat <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

and:

bash <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

This on the other hand is not an heredocument, but worked:

# CRONTAB
echo "
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
" | crontab

 

I thus wonder if it's even possible with heredocument.

Is it possible to print to crontab with an heredocument?

I tried these but failed:

cat <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

and:

bash <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

This on the other hand is not an heredocument, but worked:

# CRONTAB
echo "
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
" | crontab

 

I thus wonder if it's even possible with heredocument.

Is it possible to print to crontab with an heredocument?

I tried these but failed:

cat <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

and:

bash <<-"CRONTAB" > crontab
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
CRONTAB

This on the other hand is not an heredocument, but worked:

# CRONTAB
echo "
    0 0 * * * cat /dev/null > /var/mail/root
    0 1 * * 0 certbot renew -q
" | crontab

I thus wonder if it's even possible with heredocument.

2 edited tags
| link
1
source | link