Keep file data always available to Bash, without repeated execution (also after reboot)
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a file named ~/myScripts/assignments.sh
which contains various assignments such as variables and aliases. Here's a taste from that file:
drt="/var/www/html"
rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"
alias drt="cd $drt"
alias rss="$rss"
I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.
Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot
).
To achieve that, I thought of the following lousy script:
source ~/myScripts/assignments.sh # Immediate availability;
printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"
crontab <<-"CRONTAB"
0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
CRONTAB
What will be a good approach to achieve the state I described above?
Update
The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh
inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc
in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.
bash command-line variable alias reboot
add a comment |Â
up vote
0
down vote
favorite
I have a file named ~/myScripts/assignments.sh
which contains various assignments such as variables and aliases. Here's a taste from that file:
drt="/var/www/html"
rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"
alias drt="cd $drt"
alias rss="$rss"
I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.
Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot
).
To achieve that, I thought of the following lousy script:
source ~/myScripts/assignments.sh # Immediate availability;
printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"
crontab <<-"CRONTAB"
0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
CRONTAB
What will be a good approach to achieve the state I described above?
Update
The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh
inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc
in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.
bash command-line variable alias reboot
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file named ~/myScripts/assignments.sh
which contains various assignments such as variables and aliases. Here's a taste from that file:
drt="/var/www/html"
rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"
alias drt="cd $drt"
alias rss="$rss"
I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.
Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot
).
To achieve that, I thought of the following lousy script:
source ~/myScripts/assignments.sh # Immediate availability;
printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"
crontab <<-"CRONTAB"
0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
CRONTAB
What will be a good approach to achieve the state I described above?
Update
The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh
inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc
in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.
bash command-line variable alias reboot
I have a file named ~/myScripts/assignments.sh
which contains various assignments such as variables and aliases. Here's a taste from that file:
drt="/var/www/html"
rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"
alias drt="cd $drt"
alias rss="$rss"
I use these assignments frequently from the moment I finished installing my operating system, especially to write neater scripts for installation, configuration and maintenance of my webserver and adjacent software.
Thus, it's vital that this file will always be exported, that its data will always be available in all Bash sessions, immediately after any Bash session has started (also after a reboot
).
To achieve that, I thought of the following lousy script:
source ~/myScripts/assignments.sh # Immediate availability;
printf "n%s" "source ~/myScripts/assignments.sh" >> ~/.profile
cat > "cron_daily.sh" <<< "source ~/myScripts/assignments.sh"
crontab <<-"CRONTAB"
0 0 * * * ~/myScripts/cron_daily.sh # Permanent availability (after the one minute gap);
CRONTAB
What will be a good approach to achieve the state I described above?
Update
The reason I'd think to avoid sourcing the file, then add source ~/myScripts/assignments.sh
inside bash.bashrc is that I've seen some devops reluctant from sourcing bash.bashrc
in general. Although, when the file isn't customized, or has just such small change it is generally not a problem.
bash command-line variable alias reboot
edited Feb 9 at 7:30
asked Feb 8 at 8:58
user9303970
123224
123224
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments
and source it globally from /etc/bash.bashrc
.
Append this into /etc/bash.bashrc
:
source /etc/assignments
That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments
and source it globally from /etc/bash.bashrc
.
Append this into /etc/bash.bashrc
:
source /etc/assignments
That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.
add a comment |Â
up vote
7
down vote
accepted
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments
and source it globally from /etc/bash.bashrc
.
Append this into /etc/bash.bashrc
:
source /etc/assignments
That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments
and source it globally from /etc/bash.bashrc
.
Append this into /etc/bash.bashrc
:
source /etc/assignments
That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments
and source it globally from /etc/bash.bashrc
.
Append this into /etc/bash.bashrc
:
source /etc/assignments
That way, you have all your definitions available in all bash-sessions, for every user, and can maintain the information in a separate file.
edited Feb 9 at 21:20
Jeff Schaller
31.3k846105
31.3k846105
answered Feb 8 at 9:57
Stefan M
8101617
8101617
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422745%2fkeep-file-data-always-available-to-bash-without-repeated-execution-also-after%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password