LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   regex with "if" does not work (https://www.linuxquestions.org/questions/linux-enterprise-47/regex-with-if-does-not-work-932332/)

DrizzyDrake 03-02-2012 07:34 AM

regex with "if" does not work
 
Hello All

I'am setting up 2 jumpservers (in a Cluster) at my Company and i'm stuck with a little problem here.

The idea is: If the User is created, /etc/skel will copy a script into the homedir of every user.
This script should be executable only by regular users, which names are like "tkfoo". tk or tx at the beginning, followed by three letters and/or numbers.

If i execute this script with root, it will not allow to sync the homedir. When i execute this with a tk... or tx... user it should run and sync the homedirs, but it doesn't.
I get the Error message: "You are not permitted to rsync your homedir as user $USER, you have to be tk*** or tx***"
I thought that =~ should work, but it doesnt. I don't know how i should get it to work, any help is appreciated.

Anyways, here is the tiny script:
Code:

#!/bin/bash
DEST="server02"
BACKDIR="/home/$USER"
DESTDIR="/home/$USER"
OPTS="-avvz --delete --exclude="^.*" --log-file=/var/log/rsync.log"

if [[ "$USER" =~ "t[k|x]..." ]]; then
    rsync $OPTS $BACKDIR $USER@$DEST:$DESTDIR
else
    echo "You are not permitted to rsync your homedir as user $USER, you have to be tk*** or tx***"
fi

I apologize for any english mistakes, I hope you can imagine what I'm trying to do.

whizje 03-02-2012 07:50 AM

try this
Code:

if [[ $USER = t[kx]* ]]; then

DrizzyDrake 03-02-2012 07:52 AM

Thanks!
 
Well that did it.
It works!
I tried like 10 different things and nothing worked.

Many thanks to you!


All times are GMT -5. The time now is 05:32 PM.