telinit 1 and run a command there
I need to do some maintenance on a bunch of Debian (Wheezy) systems, and it has to happen at run level 1. But not all machines have a keyboard and a screen; some are even located somewhere else. So I can't just go there and type in the root password to trigger the job.
So my question is how can I tell Debian to run a command right before the "Type root password or ^D" prompt?
I've tried to make a init script that only runs on run level 1, but still it was triggered before all processes where killed.
Is there a way to do this?
debian administration runlevel
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I need to do some maintenance on a bunch of Debian (Wheezy) systems, and it has to happen at run level 1. But not all machines have a keyboard and a screen; some are even located somewhere else. So I can't just go there and type in the root password to trigger the job.
So my question is how can I tell Debian to run a command right before the "Type root password or ^D" prompt?
I've tried to make a init script that only runs on run level 1, but still it was triggered before all processes where killed.
Is there a way to do this?
debian administration runlevel
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
1
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36
add a comment |
I need to do some maintenance on a bunch of Debian (Wheezy) systems, and it has to happen at run level 1. But not all machines have a keyboard and a screen; some are even located somewhere else. So I can't just go there and type in the root password to trigger the job.
So my question is how can I tell Debian to run a command right before the "Type root password or ^D" prompt?
I've tried to make a init script that only runs on run level 1, but still it was triggered before all processes where killed.
Is there a way to do this?
debian administration runlevel
I need to do some maintenance on a bunch of Debian (Wheezy) systems, and it has to happen at run level 1. But not all machines have a keyboard and a screen; some are even located somewhere else. So I can't just go there and type in the root password to trigger the job.
So my question is how can I tell Debian to run a command right before the "Type root password or ^D" prompt?
I've tried to make a init script that only runs on run level 1, but still it was triggered before all processes where killed.
Is there a way to do this?
debian administration runlevel
debian administration runlevel
edited Jul 15 '14 at 15:13
Christopher
10.5k33148
10.5k33148
asked Jul 15 '14 at 14:53
Florian FidaFlorian Fida
90969
90969
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 3 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
1
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36
add a comment |
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
1
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
1
1
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36
add a comment |
1 Answer
1
active
oldest
votes
I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.
My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.
here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.
But: Don't just try this unless you know what it does!
mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s//sbin/sulogin//opt/single/job.sh/" /etc/inittab
cat>/opt/single/job.sh<<EOF
#!/bin/bash
#restore inittab
mv -fv /opt/single/inittab /etc/inittab
#make sure no one runs this by accident
chmod -x /opt/single/job.sh
#do your thing...
mount -o remount,ro /dev/sda1
fsck.ext4 -vfp /dev/sda1
zerofree -v /dev/sda1
mount -o remount,rw /dev/sda1
#work done
reboot
EOF
chmod +x /opt/single/job.sh
telinit 1
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f144655%2ftelinit-1-and-run-a-command-there%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
I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.
My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.
here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.
But: Don't just try this unless you know what it does!
mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s//sbin/sulogin//opt/single/job.sh/" /etc/inittab
cat>/opt/single/job.sh<<EOF
#!/bin/bash
#restore inittab
mv -fv /opt/single/inittab /etc/inittab
#make sure no one runs this by accident
chmod -x /opt/single/job.sh
#do your thing...
mount -o remount,ro /dev/sda1
fsck.ext4 -vfp /dev/sda1
zerofree -v /dev/sda1
mount -o remount,rw /dev/sda1
#work done
reboot
EOF
chmod +x /opt/single/job.sh
telinit 1
add a comment |
I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.
My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.
here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.
But: Don't just try this unless you know what it does!
mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s//sbin/sulogin//opt/single/job.sh/" /etc/inittab
cat>/opt/single/job.sh<<EOF
#!/bin/bash
#restore inittab
mv -fv /opt/single/inittab /etc/inittab
#make sure no one runs this by accident
chmod -x /opt/single/job.sh
#do your thing...
mount -o remount,ro /dev/sda1
fsck.ext4 -vfp /dev/sda1
zerofree -v /dev/sda1
mount -o remount,rw /dev/sda1
#work done
reboot
EOF
chmod +x /opt/single/job.sh
telinit 1
add a comment |
I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.
My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.
here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.
But: Don't just try this unless you know what it does!
mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s//sbin/sulogin//opt/single/job.sh/" /etc/inittab
cat>/opt/single/job.sh<<EOF
#!/bin/bash
#restore inittab
mv -fv /opt/single/inittab /etc/inittab
#make sure no one runs this by accident
chmod -x /opt/single/job.sh
#do your thing...
mount -o remount,ro /dev/sda1
fsck.ext4 -vfp /dev/sda1
zerofree -v /dev/sda1
mount -o remount,rw /dev/sda1
#work done
reboot
EOF
chmod +x /opt/single/job.sh
telinit 1
I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.
My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.
here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.
But: Don't just try this unless you know what it does!
mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s//sbin/sulogin//opt/single/job.sh/" /etc/inittab
cat>/opt/single/job.sh<<EOF
#!/bin/bash
#restore inittab
mv -fv /opt/single/inittab /etc/inittab
#make sure no one runs this by accident
chmod -x /opt/single/job.sh
#do your thing...
mount -o remount,ro /dev/sda1
fsck.ext4 -vfp /dev/sda1
zerofree -v /dev/sda1
mount -o remount,rw /dev/sda1
#work done
reboot
EOF
chmod +x /opt/single/job.sh
telinit 1
answered Jul 16 '14 at 2:56
Florian FidaFlorian Fida
90969
90969
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f144655%2ftelinit-1-and-run-a-command-there%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
Why does it need to be done on runlevel 1?
– jordanm
Jul 15 '14 at 15:11
1
I need to remount the root filesystem as ro
– Florian Fida
Jul 15 '14 at 17:36