RetroFed Forum
Your home away from modern life.
Create an automated terminal command?
Post Reply
AuthorMessage
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
Quote

Newish to Linux and slowly learning lol. I recently got a podcast downloader working through rss with castget, works great. The command to get new eps that haven't been downloaded is castget -c.

Is there a way to automate this, so the command runs say every day at a set time?

26   Original
CameronDev programming.dev CameronDev@programming.dev
Joined: 2023-06-18
#2 · Quote Reply

cron/crontab are the general things you want to search for. They are used for running commands on a schedule, which is what you want.

You can also use systemd timers. Pick the one that your OS supports.

10
RotatingParts lemmy.ml RotatingParts@lemmy.ml
Joined: 2023-06-21
#3 · Quote Reply

You can set up a cron job to run a command on a schedule that you want. Here is one of many pages that explains that How to Set Up Cron Jobs on Linux (crontab Guide)

4
Static_Rocket lemmy.world Static_Rocket@lemmy.world
Joined: 2023-06-12
#4 · Quote Reply

There are users that still swear by cron, but on modern systems a systemd timer is generally advised.

29
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#5 · Quote Reply

You can set up a cron job to run a command on a schedule that you want. Here is one of many pages that explains that How to Set Up Cron Jobs on Linux (crontab Guide)

Great, thank you. I heard about cron jobs when I first switched to Linux but got overwhelmed. Appreciate the link.

3
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#6 · (edited) Quote Reply

You can set up a cron job to run a command on a schedule that you want. Here is one of many pages that explains that How to Set Up Cron Jobs on Linux (crontab Guide)

This seems way more straight forward than i remember lol. I'm on Cachy, which apparently doesn't have cron out of the box. Just installed cronie, ran crontab -e, and if I enter:

0 6 * * * * castget -c

(with spaces between 0 6 * etc?) that's it? It'll run every day at 6am?

2
wiener234 feddit.org wiener234@feddit.org
Joined: 2025-01-26
#7 · Quote Reply

You have two options that are most likely pre-installed: systemd-timer or cron

With systemd-timer you can run it as a user or as root. For your use case I would go with the user option for two reasons.

  1. The downloaded files will have the right permissions by default.
  2. Security. There is no reason why the service would need root access to your system.

For systemd-timer you need two files the .timer and the .system file.

your-timer.timer

[Unit]
Description="Run your-service.service 5min after boot and every 24 hours relative to activation time"

[Timer]
OnBootSec=5min
OnUnitActiveSec=24h
Unit=your-service.service

[Install]
WantedBy=timers.target

your-service.service

[Unit]
Description=Download new podcasts

[Service]
Type=oneshot
ExecStart=castget -c

These two files go into ~/.config/systemd/user/.
Then run systemctl --user daemon-reload and systemctl --user enable your-timer.timer --now.
If you want the service to also run if you are not logged in run sudo loginctl enable-linger youruser.

For cron it is less work. Just run cron -e and put your command in there preceded by the time it is supposed to run. The timeformat should be explained at the top of the file. I also don't know if it will run if you are not logged in.

17
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#8 · Quote Reply

You have two options that are most likely pre-installed: systemd-timer or cron With systemd-timer you can run it as a user or as root. For your use case I would go with the user option for two reasons. The downloaded files will have the right permissions by default. Security. There is no reason why the service would need root access to your system. For systemd-timer you need two files the .time...

I'm looking at cron. I just made a cronjob:

0 6 * * * castget -c

Is that it to run every day at 6am?

6
wiener234 feddit.org wiener234@feddit.org
Joined: 2025-01-26
#9 · Quote Reply

I'm looking at cron. I just made a cronjob: 0 6 * * * castget -c Is that it to run every day at 6am?

Yes this looks good to me.

1
GooeyGlob lemmy.world gooeyglob@lemmy.world
Joined: 2023-06-12
#10 · Quote Reply

I'm looking at cron. I just made a cronjob: 0 6 * * * castget -c Is that it to run every day at 6am?

One thing is you should not make assumptions about the path in cron. If it's in anywhere than /usr/bin, I would specify the path of the script/binary. Otherwise it looks great.

2
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#11 · Quote Reply

Yes this looks good to me.

Huh. That's shockingly simple.

1
wiener234 feddit.org wiener234@feddit.org
Joined: 2025-01-26
#12 · Quote Reply

I'm looking at cron. I just made a cronjob: 0 6 * * * castget -c Is that it to run every day at 6am?

Also because I just remembered and it might be relevant to you. If you shut your system down and it is not running at 6am the cron job will not run that day. With systemd-timer it would check if it missed it's run because the system was powered off and the run after boot the same day.

16
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#13 · Quote Reply

Also because I just remembered and it might be relevant to you. If you shut your system down and it is not running at 6am the cron job will not run that day. With systemd-timer it would check if it missed it's run because the system was powered off and the run after boot the same day.

Got it. My system is always on so that's no issue. Appreciate the help.

3
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#14 · Quote Reply

One thing is you should not make assumptions about the path in cron. If it's in anywhere than /usr/bin, I would specify the path of the script/binary. Otherwise it looks great.

I'll keep that in mind thanks. Haven't dipped my toes into scripts and things yet but this just opened up a world of possibilities lol

2
vole lemmy.world vole@lemmy.world
Joined: 2023-06-10
#15 · Quote Reply

I'm looking at cron. I just made a cronjob: 0 6 * * * castget -c Is that it to run every day at 6am?

In line with the advice that running as root would likely not run with the correct file permissions (and would not read the correct config files), you probably want to run castget as your desktop user. Something like sudo -u mydesktopuser -n -- castget -c

2
davel lemmy.ml davel@lemmy.ml
Joined: 2023-07-08
#16 · Quote Reply

There are users that still swear by cron, but on modern systems a systemd timer is generally advised.

If systemd is running, as it is on the great majority of distributions, then cron is running on top of it, as just another service. It’s not an either-or situation.

3
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#17 · Quote Reply

In line with the advice that running as root would likely not run with the correct file permissions (and would not read the correct config files), you probably want to run castget as your desktop user. Something like sudo -u mydesktopuser -n -- castget -c

I see. I'm the only user and the .castgetrc file that I edit for the RSS feeds is located in home. The castget command works in terminal when I type it, but it may not if cron does it? Would that be because cron installs as root? I'm on Cachyos and had to install cronie as cron wasn't preinstalled. If it doesn't work I'll try your suggestion.

I know -u is for user, what is -n -- in this case?

2
NoLemurs lemmy.world NoLemurs@lemmy.world
Joined: 2026-10-02
#18 · Quote Reply

If systemd is running, as it is on the great majority of distributions, then cron is running on top of it, as just another service. It’s not an either-or situation.

It's not. But the systemd timer has more robust logging and monitoring, and much more explicit and readable syntax.

Once you get used to systemd timers, it's really hard to see why you wouldn't use them if your system has systemd. Unless writing crontabs by hand makes you feel like a hacker I guess. I'm not even being totally sarcastic about that - there is a fun retro feel to cron.

8
aksdb lemmy.world aksdb@lemmy.world
Joined: 2024-01-17
#19 · Quote Reply

It's not. But the systemd timer has more robust logging and monitoring, and much more explicit and readable syntax. Once you get used to systemd timers, it's really hard to see why you wouldn't use them if your system has systemd. Unless writing crontabs by hand makes you feel like a hacker I guess. I'm not even being totally sarcastic about that - there is a fun retro feel to cron.

I generally like their outcome, but hate the boilerplate. I think I need somewhere around 20 lines over two different files which would otherwise be a one-liner in a cron file.

5
NoLemurs lemmy.world NoLemurs@lemmy.world
Joined: 2026-10-02
#20 · Quote Reply

I generally like their outcome, but hate the boilerplate. I think I need somewhere around 20 lines over two different files which would otherwise be a one-liner in a cron file.

Yeah. Once you spend an afternoon debugging a failing cron job, the 5 minutes needed to write the boilerplate starts to feel pretty ok though.

I've never had to spend an afternoon debugging a failing systemd timer in the years since I made the switch.

4
Sophienomenal lemmy.blahaj.zone Filetternavn@lemmy.blahaj.zone
Joined: 2024-12-03
#21 · Quote Reply

I see. I'm the only user and the .castgetrc file that I edit for the RSS feeds is located in home. The castget command works in terminal when I type it, but it may not if cron does it? Would that be because cron installs as root? I'm on Cachyos and had to install cronie as cron wasn't preinstalled. If it doesn't work I'll try your suggestion. I know -u is for user, what is -n -- in this case?

If you ever have a question about what a specific flag does for a command, type man [insert command here] and RTFM (respectfully, of course). If you need a shorthand that's less verbose, most commands have a --help or -h flag that prints out a quick overview of how to use the command and what the flags do.

2
vole lemmy.world vole@lemmy.world
Joined: 2023-06-10
#22 · (edited) Quote Reply

I see. I'm the only user and the .castgetrc file that I edit for the RSS feeds is located in home. The castget command works in terminal when I type it, but it may not if cron does it? Would that be because cron installs as root? I'm on Cachyos and had to install cronie as cron wasn't preinstalled. If it doesn't work I'll try your suggestion. I know -u is for user, what is -n -- in this case?

It would be because cron runs as the root user.

Castget probably looks at the file path $HOME/.castgetrc. For your regular user, $HOME is probably /home/myamazingusername. For the root user, $HOME is probably /root .

You can get a root terminal session by running sudo -i in a terminal console window. You can try running castget there to see what happens.

Sudo -n:

-n, --non-interactive
  Avoid prompting the user for input of any kind.  If a
  password is required for the command to run, sudo, will
  display an error message and exit.

It's just a nice thing to put in non-interactive scripts that use sudo. Sometimes you can end up with scripts that just wait endlessly for a password that will never be input because the script is being run non-interactively. The flag probably isn't needed for a cron job, because root probably can sudo as any user without a password, but it doesn't hurt either.

EDIT: I didn't know that there are user crontab entries as well. If you just used crontab -e without using sudo, then you don't need to worry about the job being run as root.

4
MonkderVierte lemmy.zip MonkderVierte@lemmy.zip
Joined: 2025-05-30
#23 · Quote Reply

There are users that still swear by cron, but on modern systems a systemd timer is generally advised.

I have a modern system without built-in mission creep.

5
robber lemmy.ml robber@lemmy.ml
Joined: 2022-11-25
#24 · Quote Reply

I'm looking at cron. I just made a cronjob: 0 6 * * * castget -c Is that it to run every day at 6am?

There are tools like crontab.guru which helped me get started.

3
Static_Rocket lemmy.world Static_Rocket@lemmy.world
Joined: 2023-06-12
#25 · Quote Reply

I have a modern system without built-in mission creep.

3
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#26 · Quote Reply

It would be because cron runs as the root user. Castget probably looks at the file path $HOME/.castgetrc. For your regular user, $HOME is probably /home/myamazingusername. For the root user, $HOME is probably /root . You can get a root terminal session by running sudo -i in a terminal console window. You can try running castget there to see what happens. Sudo -n: -n, --non-interactive Avoid pro...

This was really interesting, thanks. Something I'll keep in mind for sure, but I did set it up with crontab -e so maybe I'm all good. Gonna play around with it some more over the next few days, there's so much to learn. Linux is amazing

2
imminent_nebula lemmy.ca imminent_nebula@lemmy.ca
Joined: 2025-07-22
#27 · Quote Reply

If you ever have a question about what a specific flag does for a command, type man [insert command here] and RTFM (respectfully, of course). If you need a shorthand that's less verbose, most commands have a --help or -h flag that prints out a quick overview of how to use the command and what the flags do.

Excellent thank you

1
GooeyGlob lemmy.world gooeyglob@lemmy.world
Joined: 2023-06-12
#28 · Quote Reply

I'll keep that in mind thanks. Haven't dipped my toes into scripts and things yet but this just opened up a world of possibilities lol

Crom and bash are definitely gateway drugs to automation, hehe. Enjoy!

1
chaosCruiser futurology.today chaosCruiser@futurology.today
Joined: 2024-05-14
#29 · Quote Reply

Also because I just remembered and it might be relevant to you. If you shut your system down and it is not running at 6am the cron job will not run that day. With systemd-timer it would check if it missed it's run because the system was powered off and the run after boot the same day.

Very interesting. I’m beginning to see why so many people are recommending systemd instead of cron.

2
Wolf314159 startrek.website Wolf314159@startrek.website
Joined: 2024-07-03
#30 · Quote Reply

There are users that still swear by cron, but on modern systems a systemd timer is generally advised.

They don't even know cron exists and you're going to throw them to the wolves by suggesting Systemd? That's like calling in a drone strike to swat a mosquito.

3
Post Reply
Back to top