Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm writing a bash-script that will be run as a cron job everyday. Very basic, I was wanting to change the wallpaper daily. I have mint-14 with mate.

The thing I'm getting caught up on right now is, I want to have the user's home path detected automatically. If I don't do this I would have to change it for all other users that run the script.

So far I have tried:

homedir=${HOME}/Pictures/daily

mateconftool-2 -t string -s /desktop/mate/background/picture_filename $homedir;

This doesn't work but,

echo $homedir

Prints out the correct path?

EDIT:

When I tried ~user like @vonbrand was suggesting there is no difference.

mateconftool-2 -t string -s /desktop/mate/background/picture_filename ~user/Pictures/daily;
share|improve this question
    
At least csh, bash use ~user for the user's home. It is the value of the shell variable HOME for each user. –  vonbrand Mar 3 '13 at 0:00
    
I've tried to change the above script example to use ~user with the mateconftool-2 command but, its not working? I've edited my post to reflect this. –  tijko Mar 3 '13 at 0:49

1 Answer 1

up vote 4 down vote accepted

$HOME is not set in cron, so put this in a script, and let your cron job execute that instead,

(Remember to set the execution bit for that script with chmod +x XX)

#!/bin/bash

mateconftool-2 -t string -s /desktop/mate/background/picture_filename ~/Pictures/daily

Or in your cronjob,

HOME="$(getent passwd $USER | awk -F ':' '{print $6}')"
homedir=${HOME}/Pictures/daily
share|improve this answer
    
@tijko getent returns colon separated lines, so $6 would be the sixth element, which is your home directory –  warl0ck Mar 3 '13 at 1:18
    
Honest question: how portable is it? Is it safe to assume that the user's home directory is the 6th element of the /etc/password file for several (most) unices? –  rahmu Mar 3 '13 at 23:23
    
@rahmu hmm, I'm not sure, but the OP runs mint, so that's okay here ... –  warl0ck Mar 3 '13 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.