Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello World,
i'm developing bash script to insert HISTTIMEFORMAT into /etc/profile to activate date and time in history file for all users linux starting from a server to all server of DataCenter.
I done some proofs but statemente echo send error: i put script follow:
Code:
#!/bin/bash
> /tmp/histDateTime.sh
i=/tmp/server_list.txt
c="cp /etc/profile /etc/profile_bck"
d="echo 'export HISTTIMEFORMAT="%d/%m/%y %T"' >> /etc/profile"
cat $i | while read A
do
cat <<EOF >> /tmp/histDateTime.sh
ssh $A "$c" ;"$d"
EOF
done
sh /tmp/histDateTime.sh
I think also use some variable to separate data as:
Code:
#!/bin/bash
> /tmp/histDateTime.sh
i="/home/user/scripts/asset.csv"
c="cp /etc/profile /etc/profile_bck"
d=('export HISTTIMEFORMAT="%d/%m/%y %T"')
e="/etc/profile"
cat $i | while read A
do
ssh $A "$c" ; "$d" >> "$e"
but this goes error too :_(
I'm sure to not be master in bash script, so please if you can give me help i thank you forever.
Best regards
Enrico
Last edited by MienMatrix; 06-24-2022 at 07:38 AM.
It might help knowing what distribution is running on the servers.
I would create a file that contains your export command and then transfer it to the server's /etc/profile.d directory versus appending the command to the /etc/profile file.
You do have to log into the server as root or run a sudo command if your remote user has sudo privileges but it gets a little tricky if you need to be able to enter your password.
It might help knowing what distribution is running on the servers.
I would create a file that contains your export command and then transfer it to the server's /etc/profile.d directory versus appending the command to the /etc/profile file.
You do have to log into the server as root or run a sudo command if your remote user has sudo privileges but it gets a little tricky if you need to be able to enter your password.
You also need a space following the %T i.e
Code:
export HISTTIMEFORMAT="%d/%m/%y %T "
Thanks for replay,
i explain my situation:
Operation system for server data center is RedHat version (about 600 servers more or less)
I'd like use a bridge server that has direct access to all servers of data center as root (sure), list server in file txt, with protocoll ssh. Right, i need this script to insert HISTTIMEFORMAT string into /etc/profile (after made a copy) to activate date and time in all users's history file.
I'll try your code also, thank you
let me check all solution
see you after
Enrico
Last edited by MienMatrix; 06-24-2022 at 05:14 AM.
Then as suggested I would copy the command as a file to the /etc/profile.d directory instead of appending to /etc/profile. /etc/profile runs the scripts in /etc/profile.d
Per Redhat
Quote:
First of all, the files in the /etc directory are global for all users, but should really avoid changing them if at all possible. If need to modify the global settings, you can use /etc/profile.d (this is to prevent your changes from getting wiped out when packages are upgraded).
Then as suggested I would copy the command as a file to the /etc/profile.d directory instead of appending to /etc/profile. /etc/profile runs the scripts in /etc/profile.d
Per Redhat
Ok
So, if I understand correctly: if I insert in the path /etc/profile.d a file.sh containing
export HISTTIMEFORMAT = "% d /% m /% y% T"
export HISTTIMEFORMAT
into
/etc/profile.d/history.sh
history.sh would run automatically?
This it will be too much simple, because can create file history.sh and with scp script send in all server, right?
Ok
So, if I understand correctly: if I insert in the path /etc/profile.d a file.sh containing
export HISTTIMEFORMAT = "% d /% m /% y% T"
export HISTTIMEFORMAT
into
/etc/profile.d/history.sh
history.sh would run automatically?
This it will be too much simple, because can create file history.sh and with scp script send in all server, right?
Thanks a lot
Regard
Enrico
yes, that will be "automagically" executed together with /etc/profile
But it is syntactically incorrect, space is not allowed after/before = (equal sign).
yes, that will be "automagically" executed together with /etc/profile
But it is syntactically incorrect, space is not allowed after/before = (equal sign).
IT WORKS, GREAT!
spaces there aren't in command, maybe is bug of quote.
Thank you very much to solve my issue and thank to all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.