LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2019, 09:15 AM   #16
xray55
LQ Newbie
 
Registered: Aug 2019
Posts: 19

Original Poster
Rep: Reputation: Disabled

firerat,

The way you're wring your code vs the way turbo wrote it. What is that php/python? I've cheated my way thru that code before not knowing what it is for example some config files nginx/dovecot etc. It's nerve wracking. It has to be perfect or fails.
 
Old 08-26-2019, 09:21 AM   #17
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
Quote:
Originally Posted by xray55 View Post
firerat,

The way you're wring your code vs the way turbo wrote it. What is that php/python? I've cheated my way thru that code before not knowing what it is for example some config files nginx/dovecot etc. It's nerve wracking. It has to be perfect or fails.
nah, that is just bash
everytime I think about learning python/perl I revert to bash
not found the right project yet
 
Old 08-26-2019, 09:23 AM   #18
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,112
Blog Entries: 3

Rep: Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003
Code costs to write, and it costs to read. However, since it is read more than it is written the emphasis when writing needs to be on simplicity and clarity in order to reduce the burden of reading it. Your future self will thank you.

Also, bash is a lot fancier than standardize POSIX shell.

However, that said, if it is time for code golf then say the word and the floodgates shall open...
 
1 members found this post helpful.
Old 08-26-2019, 09:42 AM   #19
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,078

Rep: Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903
what I came up with. I am on FreeBSD at the moment so somethings maybe need to be changed to conform with Linux, but the logic should be sound.
Code:
#!/usr/bin/env bash

read -p "Enter name of USER you want to add dir in the " user

sudo mkdir -pv /home/$user/main/foldera
sudo mkdir -pv /home/$user/main/folderb

# the only draw back in chown is the group, if user system
#does not use user name as primary group get it first to 
#side track any issue it may cause if group does not match up
#with user name.
#using id
echo $user
getgroup=$(id $user)
echo;echo "groups are $getgroup"
pgroup=$( echo $getgroup | awk '/gid=/ {print $1}' | egrep -o [a-zA-z] | tr '\n' ' ' | rev | cut -c -10 | rev | sed 's/ //g')
echo;echo "gid : pgroup is $pgroup"
echo
echo "Ownership before change"
echo
ls -la /home/$user/main/foldera
ls -la /home/$user/main/folderb

sudo chown $user:$pgroup /home/$user/main/foldera
sudo chown $user:$pgroup /home/$user/main/folderb
echo "Ownership after  change"
echo
ls -la /home/$user/main/foldera
ls -la /home/$user/main/folderb
results
Code:
[userx@FreeBSD64ssd testscripts]$ ./makedirs
Enter name of USER you want to add dir in the userx
/home/userx/main
/home/userx/main/foldera
/home/userx/main/folderb
userx

groups are uid=1000(userx) gid=1000(userx) groups=1000(userx),0(wheel),5(operator),44(video)

gid : pgroup is userx

Ownership before change

total 16
drwxr-xr-x  2 root  userx  512 Aug 26 09:40 .
drwxr-xr-x  4 root  userx  512 Aug 26 09:40 ..
total 16
drwxr-xr-x  2 root  userx  512 Aug 26 09:40 .
drwxr-xr-x  4 root  userx  512 Aug 26 09:40 ..
Ownership after  change

total 16
drwxr-xr-x  2 userx  userx  512 Aug 26 09:40 .
drwxr-xr-x  4 root   userx  512 Aug 26 09:40 ..
total 16
drwxr-xr-x  2 userx  userx  512 Aug 26 09:40 .
drwxr-xr-x  4 root   userx  512 Aug 26 09:40 ..
of course you can replace that last line with
Code:
sudo chown $user:$pgroup /home/$user/main -R
you should also be able to just side track that assignment of the group (maybe) and just use the user name for the change.
Code:
sudo chown $user: /home/$user/main -R

Last edited by BW-userx; 08-26-2019 at 10:10 AM.
 
Old 08-26-2019, 12:55 PM   #20
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 81

Rep: Reputation: 22
Quote:
Originally Posted by xray55 View Post
Hi guys,

I want to make a small linux script to run these commands. When running the script


I want the script to ask me; ENTER USERNAME
-- That user will already be a unix user and will already have a /home directory so all I want the script to do is input what I type as username into these commands

The script then runs these 3 commands with that username


sudo mkdir /home/THATUSERNAME/main/foldera
sudo mkdir /home/THATUSERNAME/main/folderb
sudo chown -R THATUSERNAME:THATUSERNAME /home/THATUSERNAME/main

Its a repetitive thing I have to run daily.

Any help is much appreciated..
Instead of asking, you'll have to tell it when you run the command
folderab THATUSER
Code:
#!/bin/bash
#folderab user
sudo mkdir /home/$1/main/foldera
sudo mkdir /home/$1/main/folderb
sudo chown -R $1:$1 /home/$1/main
it's crude, no checking - straight forward. This is presuming the commands work as presented.
 
Old 08-26-2019, 01:51 PM   #21
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,844

Rep: Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320
Or perhaps:
Code:
sudo myscript user1 user2 user3
myscript:
Code:
#!/bin/bash
for i in "$@"; do
    su "$i" -c 'mkdir -p ~/main/foldera ~/main/folderb'
done
Though I think users' home directories should be left alone; souch media-sharing directories should go under /var/local/cutecats or someplace similar.

Last edited by NevemTeve; 08-26-2019 at 02:01 PM.
 
Old 08-26-2019, 04:14 PM   #22
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
Quote:
Originally Posted by NevemTeve View Post
Or perhaps:
Though I think users' home directories should be left alone; souch media-sharing directories should go under /var/local/cutecats or someplace similar.
yeah, but also adds some complexity
I assume some kind of disk quota is in force, that would need to be expanded.

sure wouldn't be much of a hassle... but we are all busy replacing a simple list of trival commands with a basic shell script
 
Old 08-27-2019, 07:19 AM   #23
xray55
LQ Newbie
 
Registered: Aug 2019
Posts: 19

Original Poster
Rep: Reputation: Disabled
Guys,

I'm using my new bash script. I'm super happy and now I have so much info from this thread to expand out and do other things. Again, thanks for everyone's input and assistance. You're all brilliant.
 
Old 08-27-2019, 07:29 AM   #24
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
now that you have a taste for bash

https://mywiki.wooledge.org/BashGuide

https://www.tldp.org/LDP/Bash-Beginners-Guide/html/
 
Old 08-27-2019, 07:54 AM   #25
xray55
LQ Newbie
 
Registered: Aug 2019
Posts: 19

Original Poster
Rep: Reputation: Disabled
One step at a time Firerat, I'm just getting comfortable with "Hello World"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] little help on making batch sfv files steve51184 Linux - Desktop 7 06-10-2016 04:37 AM
[SOLVED] how to write a batch file in linux?and what are batch(.bat) file benefits? karthilin Linux - Newbie 8 10-15-2012 02:10 PM
Making a batch shell script to convert, merge and append (join) movie's to mkv mnt_schred Programming 8 12-07-2009 11:51 AM
Making a batch/cron for tar command ? centosfan Linux - Server 2 08-19-2008 04:29 PM
Change batch script to shell script alan.belizario Linux - Software 1 03-30-2005 01:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration