centos 7 execute remote script from localUseful Command-line Commands on Windowssudo [ no tty present and no askpass program specified ] [ can't stat /var/run/sudo: Permission denied ]Use rsync to upload files from local to remote server from inside php script without typing passwordRsync when run in cron doesnt work. Rsync between Mac Os x Server and Linux Centosrsync not deleting foldersHow do I write an rsync exclude for a directory tree with names containing spaces?Rsync - Recursively Include Few of Many Folders in One StatementI'm trying to use “aws s3 sync” on my EC2 instance. Is the '--exclude' option broken?rsync backup remote server maintaining groups and ownerRsync to remote server and change file / directory ownerships
"How can you guarantee that you won't change/quit job after just couple of months?" How to respond?
What was the Shuttle Carrier Aircraft escape tunnel?
Why do even high-end cameras often still include normal (non-cross-type) AF sensors?
How does DC work with natural 20?
Would it be a copyright violation if I made a character’s full name refer to a song?
Silly doubt about tidal effects and Einstein Field Equations
How large would a mega structure have to be to host 1 billion people indefinitely?
Loss of power when I remove item from the outlet
Why do all the teams that I have worked with always finish a sprint without completion of all the stories?
Are springs compressed by energy, or by momentum?
When can you leave off “le/la” to say “it” in French?
Array initialization optimization
Heavily limited premature compiler translates text into excecutable python code
Why are < or > required to use /dev/tcp
How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?
Should developer taking test phones home or put in office?
How did Bellatrix know about the Philosopher's Stone?
Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?
Is "Busen" just the area between the breasts?
What size of powerbank will I need to power a phone and DSLR for 2 weeks?
What is the origin of Scooby-Doo's name?
Dates on degrees don’t make sense – will people care?
Is it damaging to turn off a small fridge for two days every week?
What does the hyphen "-" mean in "tar xzf -"?
centos 7 execute remote script from local
Useful Command-line Commands on Windowssudo [ no tty present and no askpass program specified ] [ can't stat /var/run/sudo: Permission denied ]Use rsync to upload files from local to remote server from inside php script without typing passwordRsync when run in cron doesnt work. Rsync between Mac Os x Server and Linux Centosrsync not deleting foldersHow do I write an rsync exclude for a directory tree with names containing spaces?Rsync - Recursively Include Few of Many Folders in One StatementI'm trying to use “aws s3 sync” on my EC2 instance. Is the '--exclude' option broken?rsync backup remote server maintaining groups and ownerRsync to remote server and change file / directory ownerships
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm working on a script to sync a folder from Windows to a Linux server with Rsync and I manage to get it work with git bash and the rsync executable.
In Centso I added the syncinguser to the sudoer -> syncinguser ALL=NOPASSWD:/usr/bin/rsync to allow the execution of Rsync, how can I allow the same user to run a .sh file to complete the sync process or a php command?
I want to sync a Laravel application so I need to run the command php artisan cache:clear and php artisan config:cache after the sync has finished.
I would also like to change owner:group like chown -R user:psacln * but I'm quite happy with the fact that doesn't change the rights on the folders E.g: 0777 permission on the public folder.
This is my script in windows so far:
rsync -rt --chown=user:group (being ignored I think because user's permissions)
--exclude ".env" --exclude "storage" --exclude "public/storage" --progress
--rsync-path="sudo rsync" -e "ssh -p <port>"
'/c/path/to/local/folder/' syncinguser@<ip address>:/remote/path/
how can I add something like this after the sync:
ssh yncinguser@<ip address> php artisan cache:clear
ssh syncinguser@<ip address> php artisan config:cache
// OR
ssh syncinguser@<ip address>:/remote/path/to/completesync.sh
where completesync.sh will run the 2 php artisan command and apply recursively the owner:group of all files/folders as when they come from windows they are all root:root
I cannot connect as a root because we blocked it, you need to connect as a normal user and then switch to root.
ssh -p <ssh port> syncinguser@<IP ADDRESSED> '/path/to/script.sh'
permissions denied, same if I connect as a normal user
linux windows rsync
add a comment |
I'm working on a script to sync a folder from Windows to a Linux server with Rsync and I manage to get it work with git bash and the rsync executable.
In Centso I added the syncinguser to the sudoer -> syncinguser ALL=NOPASSWD:/usr/bin/rsync to allow the execution of Rsync, how can I allow the same user to run a .sh file to complete the sync process or a php command?
I want to sync a Laravel application so I need to run the command php artisan cache:clear and php artisan config:cache after the sync has finished.
I would also like to change owner:group like chown -R user:psacln * but I'm quite happy with the fact that doesn't change the rights on the folders E.g: 0777 permission on the public folder.
This is my script in windows so far:
rsync -rt --chown=user:group (being ignored I think because user's permissions)
--exclude ".env" --exclude "storage" --exclude "public/storage" --progress
--rsync-path="sudo rsync" -e "ssh -p <port>"
'/c/path/to/local/folder/' syncinguser@<ip address>:/remote/path/
how can I add something like this after the sync:
ssh yncinguser@<ip address> php artisan cache:clear
ssh syncinguser@<ip address> php artisan config:cache
// OR
ssh syncinguser@<ip address>:/remote/path/to/completesync.sh
where completesync.sh will run the 2 php artisan command and apply recursively the owner:group of all files/folders as when they come from windows they are all root:root
I cannot connect as a root because we blocked it, you need to connect as a normal user and then switch to root.
ssh -p <ssh port> syncinguser@<IP ADDRESSED> '/path/to/script.sh'
permissions denied, same if I connect as a normal user
linux windows rsync
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
the final script will bersync / php artisan cache:clear / php artisan config:cacheand in the one that will runs between the 2 linux server alsophp artisan down / php artisan downbefore and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash
– Sebastiano
Jun 5 at 15:58
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01
add a comment |
I'm working on a script to sync a folder from Windows to a Linux server with Rsync and I manage to get it work with git bash and the rsync executable.
In Centso I added the syncinguser to the sudoer -> syncinguser ALL=NOPASSWD:/usr/bin/rsync to allow the execution of Rsync, how can I allow the same user to run a .sh file to complete the sync process or a php command?
I want to sync a Laravel application so I need to run the command php artisan cache:clear and php artisan config:cache after the sync has finished.
I would also like to change owner:group like chown -R user:psacln * but I'm quite happy with the fact that doesn't change the rights on the folders E.g: 0777 permission on the public folder.
This is my script in windows so far:
rsync -rt --chown=user:group (being ignored I think because user's permissions)
--exclude ".env" --exclude "storage" --exclude "public/storage" --progress
--rsync-path="sudo rsync" -e "ssh -p <port>"
'/c/path/to/local/folder/' syncinguser@<ip address>:/remote/path/
how can I add something like this after the sync:
ssh yncinguser@<ip address> php artisan cache:clear
ssh syncinguser@<ip address> php artisan config:cache
// OR
ssh syncinguser@<ip address>:/remote/path/to/completesync.sh
where completesync.sh will run the 2 php artisan command and apply recursively the owner:group of all files/folders as when they come from windows they are all root:root
I cannot connect as a root because we blocked it, you need to connect as a normal user and then switch to root.
ssh -p <ssh port> syncinguser@<IP ADDRESSED> '/path/to/script.sh'
permissions denied, same if I connect as a normal user
linux windows rsync
I'm working on a script to sync a folder from Windows to a Linux server with Rsync and I manage to get it work with git bash and the rsync executable.
In Centso I added the syncinguser to the sudoer -> syncinguser ALL=NOPASSWD:/usr/bin/rsync to allow the execution of Rsync, how can I allow the same user to run a .sh file to complete the sync process or a php command?
I want to sync a Laravel application so I need to run the command php artisan cache:clear and php artisan config:cache after the sync has finished.
I would also like to change owner:group like chown -R user:psacln * but I'm quite happy with the fact that doesn't change the rights on the folders E.g: 0777 permission on the public folder.
This is my script in windows so far:
rsync -rt --chown=user:group (being ignored I think because user's permissions)
--exclude ".env" --exclude "storage" --exclude "public/storage" --progress
--rsync-path="sudo rsync" -e "ssh -p <port>"
'/c/path/to/local/folder/' syncinguser@<ip address>:/remote/path/
how can I add something like this after the sync:
ssh yncinguser@<ip address> php artisan cache:clear
ssh syncinguser@<ip address> php artisan config:cache
// OR
ssh syncinguser@<ip address>:/remote/path/to/completesync.sh
where completesync.sh will run the 2 php artisan command and apply recursively the owner:group of all files/folders as when they come from windows they are all root:root
I cannot connect as a root because we blocked it, you need to connect as a normal user and then switch to root.
ssh -p <ssh port> syncinguser@<IP ADDRESSED> '/path/to/script.sh'
permissions denied, same if I connect as a normal user
linux windows rsync
linux windows rsync
edited Jun 6 at 18:24
Sebastiano
asked Jun 5 at 15:39
SebastianoSebastiano
1237
1237
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
the final script will bersync / php artisan cache:clear / php artisan config:cacheand in the one that will runs between the 2 linux server alsophp artisan down / php artisan downbefore and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash
– Sebastiano
Jun 5 at 15:58
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01
add a comment |
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
the final script will bersync / php artisan cache:clear / php artisan config:cacheand in the one that will runs between the 2 linux server alsophp artisan down / php artisan downbefore and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash
– Sebastiano
Jun 5 at 15:58
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
the final script will be
rsync / php artisan cache:clear / php artisan config:cache and in the one that will runs between the 2 linux server also php artisan down / php artisan down before and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash– Sebastiano
Jun 5 at 15:58
the final script will be
rsync / php artisan cache:clear / php artisan config:cache and in the one that will runs between the 2 linux server also php artisan down / php artisan down before and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash– Sebastiano
Jun 5 at 15:58
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01
add a comment |
1 Answer
1
active
oldest
votes
OK, so you need two scripts: one on the source machine, and another one on the destination machine. The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"
And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as root
Be careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.sh
Last, modify /etc/sudoers on the destination machine so that "syncuser" can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.sh
Now running the script on the source machine should complete the whole process in one operation.
I change the permission to777and in visudosyncuser ALL=(ALL) NOPASSWD:ALLbut nothing to do, I always have permission denied. I was trying to do a simplechown -R ...it runs if I use that user on the server and i run the script manual but not from remote
– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
now it works :) thanks a lot
– Sebastiano
2 days ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970247%2fcentos-7-execute-remote-script-from-local%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
OK, so you need two scripts: one on the source machine, and another one on the destination machine. The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"
And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as root
Be careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.sh
Last, modify /etc/sudoers on the destination machine so that "syncuser" can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.sh
Now running the script on the source machine should complete the whole process in one operation.
I change the permission to777and in visudosyncuser ALL=(ALL) NOPASSWD:ALLbut nothing to do, I always have permission denied. I was trying to do a simplechown -R ...it runs if I use that user on the server and i run the script manual but not from remote
– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
now it works :) thanks a lot
– Sebastiano
2 days ago
add a comment |
OK, so you need two scripts: one on the source machine, and another one on the destination machine. The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"
And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as root
Be careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.sh
Last, modify /etc/sudoers on the destination machine so that "syncuser" can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.sh
Now running the script on the source machine should complete the whole process in one operation.
I change the permission to777and in visudosyncuser ALL=(ALL) NOPASSWD:ALLbut nothing to do, I always have permission denied. I was trying to do a simplechown -R ...it runs if I use that user on the server and i run the script manual but not from remote
– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
now it works :) thanks a lot
– Sebastiano
2 days ago
add a comment |
OK, so you need two scripts: one on the source machine, and another one on the destination machine. The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"
And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as root
Be careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.sh
Last, modify /etc/sudoers on the destination machine so that "syncuser" can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.sh
Now running the script on the source machine should complete the whole process in one operation.
OK, so you need two scripts: one on the source machine, and another one on the destination machine. The script on the source machine should be something like:
rsync ... ... ... syncuser@destination:/dest/path
ssh syncuser@destination "sudo /some/path/to/completesync.sh"
And on the destination machine, the script /some/path/to/completesync.sh which contains something like this:
#!/bin/sh
php artisan cache:clear
php artisan config:cache
# whatever else you need to run as root
Be careful to have restricted rights on this script:
chown root:root /path/to/completesync.sh && chmod 700 /path/to/completesync.sh
Last, modify /etc/sudoers on the destination machine so that "syncuser" can run both rsync and your script as root:
syncuser ALL=NOPASSWD: /usr/bin/rsync, /path/to/completesync.sh
Now running the script on the source machine should complete the whole process in one operation.
edited Jun 10 at 16:50
answered Jun 6 at 17:08
wazooxwazoox
4,98442349
4,98442349
I change the permission to777and in visudosyncuser ALL=(ALL) NOPASSWD:ALLbut nothing to do, I always have permission denied. I was trying to do a simplechown -R ...it runs if I use that user on the server and i run the script manual but not from remote
– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
now it works :) thanks a lot
– Sebastiano
2 days ago
add a comment |
I change the permission to777and in visudosyncuser ALL=(ALL) NOPASSWD:ALLbut nothing to do, I always have permission denied. I was trying to do a simplechown -R ...it runs if I use that user on the server and i run the script manual but not from remote
– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
now it works :) thanks a lot
– Sebastiano
2 days ago
I change the permission to
777 and in visudo syncuser ALL=(ALL) NOPASSWD:ALL but nothing to do, I always have permission denied. I was trying to do a simple chown -R ... it runs if I use that user on the server and i run the script manual but not from remote– Sebastiano
Jun 7 at 10:37
I change the permission to
777 and in visudo syncuser ALL=(ALL) NOPASSWD:ALL but nothing to do, I always have permission denied. I was trying to do a simple chown -R ... it runs if I use that user on the server and i run the script manual but not from remote– Sebastiano
Jun 7 at 10:37
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
Uh, of course it misses the "sudo" command in the first script :)
– wazoox
Jun 10 at 16:48
1
1
now it works :) thanks a lot
– Sebastiano
2 days ago
now it works :) thanks a lot
– Sebastiano
2 days ago
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f970247%2fcentos-7-execute-remote-script-from-local%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You need to write a shell script. What's the question exactly? What you've shown isn't really a script, but a single command. A script is a text file with a series of commands, with eventual flow control (conditions checks, etc).
– wazoox
Jun 5 at 15:54
the final script will be
rsync / php artisan cache:clear / php artisan config:cacheand in the one that will runs between the 2 linux server alsophp artisan down / php artisan downbefore and after to run the sync and cleaning the cache, it's not a really complex script, just an automation of some commands. that command is saved in a .sh file in windows that i run calling it through the git bash– Sebastiano
Jun 5 at 15:58
OK, but I don't get what you're asking or what the problem is :)
– wazoox
Jun 5 at 17:27
I've updated the question, maybe it's a bit clear now.
– Sebastiano
Jun 5 at 22:01