• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Ubuntu crontab question

Joined
Mar 11, 2008
Messages
1,008 (0.16/day)
Location
Hungary / Budapest
System Name Kincsem
Processor AMD Ryzen 9 9950X
Motherboard ASUS ProArt X870E-CREATOR WIFI
Cooling Be Quiet Dark Rock Pro 5
Memory Kingston Fury KF560C32RSK2-96 (2×48GB 6GHz)
Video Card(s) Sapphire AMD RX 7900 XT Pulse
Storage Samsung 970PRO 500GB + Samsung 980PRO 2TB + FURY Renegade 2TB+ Adata 2TB + WD Ultrastar HC550 16TB
Display(s) Acer QHD 27"@144Hz 1ms + UHD 27"@60Hz
Case Cooler Master CM 690 III
Power Supply Seasonic 1300W 80+ Gold Prime
Mouse Logitech G502 Hero
Keyboard HyperX Alloy Elite RGB
Software Windows 10-64
Benchmark Scores https://valid.x86.fr/9qw7iq https://valid.x86.fr/4d8n02 X570 https://www.techpowerup.com/gpuz/g46uc
Hello All
I have Ubuntu 24.04.1 x64 installed on my smol rig, functioning as a NAS
Added the following commands to create a report of the HDDs for me each day:
0 5 * * * date +%Y-%m-%d >> /path/storage-state.txt;uptime >> /path/storage-state.txt;df -h|grep home >> /path/storage-state.txt;/path/HDSentinel -solid >> /path/storage-state.txt

The latest addition is the first command with the date, and if I put there, none of the commands are completing,
If I just run this line in terminal with all 4 command, no problem. Each command get executed with no issue.
But in crontab it is simply behaving like it's commented out or something, with:
0 5 * * * uptime >> /path/storage-state.txt;df -h|grep home >> /path/storage-state.txt;/path/HDSentinel -solid >> /path/storage-state.txt
There is no issue, why is date so hard for my linux?
 

bug

Joined
May 22, 2015
Messages
13,945 (3.95/day)
Processor Intel i5-12600k
Motherboard Asus H670 TUF
Cooling Arctic Freezer 34
Memory 2x16GB DDR4 3600 G.Skill Ripjaws V
Video Card(s) EVGA GTX 1060 SC
Storage 500GB Samsung 970 EVO, 500GB Samsung 850 EVO, 1TB Crucial MX300 and 2TB Crucial MX500
Display(s) Dell U3219Q + HP ZR24w
Case Raijintek Thetis
Audio Device(s) Audioquest Dragonfly Red :D
Power Supply Seasonic 620W M12
Mouse Logitech G502 Proteus Core
Keyboard G.Skill KM780R
Software Arch Linux + Win10
I can't see anything apparently wrong. But I would put all that in a script and just do:
0 5 * * * storage-state.sh >> /path/storage-state.txt 2>&1

That last bit is just in case. Cron doesn't have a console and if smth errs, everything goes into oblivion.
 
Joined
Mar 11, 2008
Messages
1,008 (0.16/day)
Location
Hungary / Budapest
System Name Kincsem
Processor AMD Ryzen 9 9950X
Motherboard ASUS ProArt X870E-CREATOR WIFI
Cooling Be Quiet Dark Rock Pro 5
Memory Kingston Fury KF560C32RSK2-96 (2×48GB 6GHz)
Video Card(s) Sapphire AMD RX 7900 XT Pulse
Storage Samsung 970PRO 500GB + Samsung 980PRO 2TB + FURY Renegade 2TB+ Adata 2TB + WD Ultrastar HC550 16TB
Display(s) Acer QHD 27"@144Hz 1ms + UHD 27"@60Hz
Case Cooler Master CM 690 III
Power Supply Seasonic 1300W 80+ Gold Prime
Mouse Logitech G502 Hero
Keyboard HyperX Alloy Elite RGB
Software Windows 10-64
Benchmark Scores https://valid.x86.fr/9qw7iq https://valid.x86.fr/4d8n02 X570 https://www.techpowerup.com/gpuz/g46uc
Alright, give this to your 90% :D
But I am still curious why this "simple" way failed me.
 
Joined
Jul 29, 2020
Messages
6 (0.00/day)
Location
France
System Name 2019
Processor Intel i3 8100
Motherboard EVGA Z370 FTW
Cooling Cooler Master Hyper 212 EVO
Memory Crucial Ballistix Sport White 2*8GB @2400Mhz
Video Card(s) EVGA RTX 2060
Storage WD Blue M.2 SATA 250GB + wd3200aakx-001ca0
Case Fractal Design Meshify C
Power Supply Seasonic 550W Gold Focus Plus
Mouse Logitech G203 Prodigy
man 5 crontab:
The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.
 

bug

Joined
May 22, 2015
Messages
13,945 (3.95/day)
Processor Intel i5-12600k
Motherboard Asus H670 TUF
Cooling Arctic Freezer 34
Memory 2x16GB DDR4 3600 G.Skill Ripjaws V
Video Card(s) EVGA GTX 1060 SC
Storage 500GB Samsung 970 EVO, 500GB Samsung 850 EVO, 1TB Crucial MX300 and 2TB Crucial MX500
Display(s) Dell U3219Q + HP ZR24w
Case Raijintek Thetis
Audio Device(s) Audioquest Dragonfly Red :D
Power Supply Seasonic 620W M12
Mouse Logitech G502 Proteus Core
Keyboard G.Skill KM780R
Software Arch Linux + Win10
man 5 crontab:
Nice. I was suspecting syntax or the command trying to write to stderr. But I couldn't spot it.

@csendesmark That's not my 90%. I'm happy if I get things right 80% of the time, but I am well aware my average is well below that.
 
Joined
Mar 11, 2008
Messages
1,008 (0.16/day)
Location
Hungary / Budapest
System Name Kincsem
Processor AMD Ryzen 9 9950X
Motherboard ASUS ProArt X870E-CREATOR WIFI
Cooling Be Quiet Dark Rock Pro 5
Memory Kingston Fury KF560C32RSK2-96 (2×48GB 6GHz)
Video Card(s) Sapphire AMD RX 7900 XT Pulse
Storage Samsung 970PRO 500GB + Samsung 980PRO 2TB + FURY Renegade 2TB+ Adata 2TB + WD Ultrastar HC550 16TB
Display(s) Acer QHD 27"@144Hz 1ms + UHD 27"@60Hz
Case Cooler Master CM 690 III
Power Supply Seasonic 1300W 80+ Gold Prime
Mouse Logitech G502 Hero
Keyboard HyperX Alloy Elite RGB
Software Windows 10-64
Benchmark Scores https://valid.x86.fr/9qw7iq https://valid.x86.fr/4d8n02 X570 https://www.techpowerup.com/gpuz/g46uc
man 5 crontab:
Damn, I was totally lost on the point when I submitted the commands manually were ok.
Hindsight it is so obvious, also - I would argue on Linux has room to improve...
This one is a bit silly.
That's not my 90%
Still, I will use the script from now on, I hate when systems are handling stuff different when you expect the same.
Will not put "complex" stuff into the "simple" crontab ever again.

You can archive this
 
  • Like
Reactions: bug

Mindweaver

Moderato®™
Staff member
Joined
Apr 16, 2009
Messages
8,322 (1.45/day)
Location
Charleston, SC
System Name Tower of Power / Delliverance
Processor i7 14700K / i9-14900K
Motherboard ASUS ROG Strix Z690-A Gaming WiFi D4 / Z690
Cooling CM MasterLiquid ML360 Mirror ARGB Close-Loop AIO / Air
Memory CORSAIR Vengeance LPX 32GB (2 x 16GB) DDR4 3600 / DDR5 2x 16gb
Video Card(s) ASUS TUF Gaming GeForce RTX 4070 Ti / GeForce RTX 4080
Storage 4x Samsung 980 Pro 1TB M.2, 2x Crucial 1TB SSD / NVM3 PC801 SK hynix 1TB
Display(s) Samsung 32" Odyssy G5 Gaming 144hz 1440p, 2x LG HDR 32" 60hz 4k / 2x LG HDR 32" 60hz 4k
Case Phantek "400A" / Dell XPS 8960
Audio Device(s) Realtek ALC4080 / Sound Blaster X1
Power Supply Corsair RM Series RM750 / 750w
Mouse Razer Deathadder V3 Hyperspeed Wireless / Glorious Gaming Model O 2 Wireless
Keyboard Glorious GMMK with box-white switches / Keychron K6 pro with blue swithes
VR HMD Quest 3 (512gb) + Rift S + HTC Vive + DK1
Software Windows 11 Pro x64 / Windows 11 Pro x64
Benchmark Scores Yes
I would add backslashes in the date to escape the percent signs(%). So the percent signs are interpreted correctly by the date command rather than being treated as special characters by the shell. I just saw this and haven't had my first cup of coffee.. so you got my 20% at best here. lol

Try this it has more error logging.
Code:
0 5 * * * /bin/bash -c 'date +\%Y-\%m-\%d >> /path/storage-state.txt; uptime >> /path/storage-state.txt; df -h | grep home >> /path/storage-state.txt; /path/HDSentinel -solid >> /path/storage-state.txt' 2>> /path/error.log
 

bug

Joined
May 22, 2015
Messages
13,945 (3.95/day)
Processor Intel i5-12600k
Motherboard Asus H670 TUF
Cooling Arctic Freezer 34
Memory 2x16GB DDR4 3600 G.Skill Ripjaws V
Video Card(s) EVGA GTX 1060 SC
Storage 500GB Samsung 970 EVO, 500GB Samsung 850 EVO, 1TB Crucial MX300 and 2TB Crucial MX500
Display(s) Dell U3219Q + HP ZR24w
Case Raijintek Thetis
Audio Device(s) Audioquest Dragonfly Red :D
Power Supply Seasonic 620W M12
Mouse Logitech G502 Proteus Core
Keyboard G.Skill KM780R
Software Arch Linux + Win10
I would add backslashes in the date to escape the percent signs(%). So the percent signs are interpreted correctly by the date command rather than being treated as special characters by the shell. I just saw this and haven't had my first cup of coffee.. so you got my 20% at best here. lol

Try this it has more error logging.
Code:
0 5 * * * /bin/bash -c 'date +\%Y-\%m-\%d >> /path/storage-state.txt; uptime >> /path/storage-state.txt; df -h | grep home >> /path/storage-state.txt; /path/HDSentinel -solid >> /path/storage-state.txt' 2>> /path/error.log
@t0t0 Already pointed that out. Still, it's good practice to put everything into a script, call that from crontab and redirect outputs as needed. Works every time.

Kudos for spotting it before the coffee though, I wasn't even aware of that crontab oddity.
 

Mindweaver

Moderato®™
Staff member
Joined
Apr 16, 2009
Messages
8,322 (1.45/day)
Location
Charleston, SC
System Name Tower of Power / Delliverance
Processor i7 14700K / i9-14900K
Motherboard ASUS ROG Strix Z690-A Gaming WiFi D4 / Z690
Cooling CM MasterLiquid ML360 Mirror ARGB Close-Loop AIO / Air
Memory CORSAIR Vengeance LPX 32GB (2 x 16GB) DDR4 3600 / DDR5 2x 16gb
Video Card(s) ASUS TUF Gaming GeForce RTX 4070 Ti / GeForce RTX 4080
Storage 4x Samsung 980 Pro 1TB M.2, 2x Crucial 1TB SSD / NVM3 PC801 SK hynix 1TB
Display(s) Samsung 32" Odyssy G5 Gaming 144hz 1440p, 2x LG HDR 32" 60hz 4k / 2x LG HDR 32" 60hz 4k
Case Phantek "400A" / Dell XPS 8960
Audio Device(s) Realtek ALC4080 / Sound Blaster X1
Power Supply Corsair RM Series RM750 / 750w
Mouse Razer Deathadder V3 Hyperspeed Wireless / Glorious Gaming Model O 2 Wireless
Keyboard Glorious GMMK with box-white switches / Keychron K6 pro with blue swithes
VR HMD Quest 3 (512gb) + Rift S + HTC Vive + DK1
Software Windows 11 Pro x64 / Windows 11 Pro x64
Benchmark Scores Yes
@t0t0 Already pointed that out. Still, it's good practice to put everything into a script, call that from crontab and redirect outputs as needed. Works every time.

Kudos for spotting it before the coffee though, I wasn't even aware of that crontab oddity.
Aww yeah good catch.. I have coffee now. lol Sorry @t0t0 ! :D Thanks bug! I'm starting to see color again

also, I wanted to add yes 100% agree with putting everything into a script. Plus, it makes it easier to read if you format it correctly.
 
Joined
Mar 11, 2008
Messages
1,008 (0.16/day)
Location
Hungary / Budapest
System Name Kincsem
Processor AMD Ryzen 9 9950X
Motherboard ASUS ProArt X870E-CREATOR WIFI
Cooling Be Quiet Dark Rock Pro 5
Memory Kingston Fury KF560C32RSK2-96 (2×48GB 6GHz)
Video Card(s) Sapphire AMD RX 7900 XT Pulse
Storage Samsung 970PRO 500GB + Samsung 980PRO 2TB + FURY Renegade 2TB+ Adata 2TB + WD Ultrastar HC550 16TB
Display(s) Acer QHD 27"@144Hz 1ms + UHD 27"@60Hz
Case Cooler Master CM 690 III
Power Supply Seasonic 1300W 80+ Gold Prime
Mouse Logitech G502 Hero
Keyboard HyperX Alloy Elite RGB
Software Windows 10-64
Benchmark Scores https://valid.x86.fr/9qw7iq https://valid.x86.fr/4d8n02 X570 https://www.techpowerup.com/gpuz/g46uc
Aww yeah good catch.. I have coffee now. lol Sorry @t0t0 ! :D Thanks bug! I'm starting to see color again

also, I wanted to add yes 100% agree with putting everything into a script. Plus, it makes it easier to read if you format it correctly.
Do I need the escape char in the script tho?
 

Solaris17

Super Dainty Moderator
Staff member
Joined
Aug 16, 2005
Messages
27,186 (3.83/day)
Location
Alabama
System Name RogueOne
Processor Xeon W9-3495x
Motherboard ASUS w790E Sage SE
Cooling SilverStone XE360-4677
Memory 128gb Gskill Zeta R5 DDR5 RDIMMs
Video Card(s) MSI SUPRIM Liquid X 4090
Storage 1x 2TB WD SN850X | 2x 8TB GAMMIX S70
Display(s) 49" Philips Evnia OLED (49M2C8900)
Case Thermaltake Core P3 Pro Snow
Audio Device(s) Moondrop S8's on schitt Gunnr
Power Supply Seasonic Prime TX-1600
Mouse Razer Viper mini signature edition (mercury white)
Keyboard Monsgeek M3 Lavender, Moondrop Luna lights
VR HMD Quest 3
Software Windows 11 Pro Workstation
Benchmark Scores I dont have time for that.
Do I need the escape char in the script tho?
That is a question that is 1000 feet deep depending on host variables and system configuration. But no in your case you don’t.

I would run the script redirect output to a log and append date to it.
 
Joined
Mar 11, 2008
Messages
1,008 (0.16/day)
Location
Hungary / Budapest
System Name Kincsem
Processor AMD Ryzen 9 9950X
Motherboard ASUS ProArt X870E-CREATOR WIFI
Cooling Be Quiet Dark Rock Pro 5
Memory Kingston Fury KF560C32RSK2-96 (2×48GB 6GHz)
Video Card(s) Sapphire AMD RX 7900 XT Pulse
Storage Samsung 970PRO 500GB + Samsung 980PRO 2TB + FURY Renegade 2TB+ Adata 2TB + WD Ultrastar HC550 16TB
Display(s) Acer QHD 27"@144Hz 1ms + UHD 27"@60Hz
Case Cooler Master CM 690 III
Power Supply Seasonic 1300W 80+ Gold Prime
Mouse Logitech G502 Hero
Keyboard HyperX Alloy Elite RGB
Software Windows 10-64
Benchmark Scores https://valid.x86.fr/9qw7iq https://valid.x86.fr/4d8n02 X570 https://www.techpowerup.com/gpuz/g46uc
Checked,
My system works without the escape char.
 

Mindweaver

Moderato®™
Staff member
Joined
Apr 16, 2009
Messages
8,322 (1.45/day)
Location
Charleston, SC
System Name Tower of Power / Delliverance
Processor i7 14700K / i9-14900K
Motherboard ASUS ROG Strix Z690-A Gaming WiFi D4 / Z690
Cooling CM MasterLiquid ML360 Mirror ARGB Close-Loop AIO / Air
Memory CORSAIR Vengeance LPX 32GB (2 x 16GB) DDR4 3600 / DDR5 2x 16gb
Video Card(s) ASUS TUF Gaming GeForce RTX 4070 Ti / GeForce RTX 4080
Storage 4x Samsung 980 Pro 1TB M.2, 2x Crucial 1TB SSD / NVM3 PC801 SK hynix 1TB
Display(s) Samsung 32" Odyssy G5 Gaming 144hz 1440p, 2x LG HDR 32" 60hz 4k / 2x LG HDR 32" 60hz 4k
Case Phantek "400A" / Dell XPS 8960
Audio Device(s) Realtek ALC4080 / Sound Blaster X1
Power Supply Corsair RM Series RM750 / 750w
Mouse Razer Deathadder V3 Hyperspeed Wireless / Glorious Gaming Model O 2 Wireless
Keyboard Glorious GMMK with box-white switches / Keychron K6 pro with blue swithes
VR HMD Quest 3 (512gb) + Rift S + HTC Vive + DK1
Software Windows 11 Pro x64 / Windows 11 Pro x64
Benchmark Scores Yes
Do I need the escape char in the script tho?
What @Solaris17 said. Here is how I would put the script for readability. This will put all errors in this error.log file. :toast:

Code:
0 5 * * * {
  date +%Y-%m-%d >> /path/storage-state.txt
  uptime >> /path/storage-state.txt
  df -h | grep home >> /path/storage-state.txt
  /path/HDSentinel -solid >> /path/storage-state.txt
} 2>> /path/error.log
 
Top