View Full Version : [SOLVED] rpm scriptlet help

20th July 2011, 03:53 AM

I've been successful so far in getting my first rpm built, but it seems I am not getting something right when attempting to run a "scriptlet' in the %pre section.

Specifically, I have the following:


if [ -s /etc/myfile ] then
mv /etc/myfile /etc/myfile.bak;
touch /etc/myfile

Now, I think my logic is clear and correct, and I have read the fedora/rpm/wiki on the scriptlets section. However my rpm installs but the above code does not appear to be processing correctly - actually, not at all. IS there a #!/bin/sh needed or some other such formatting I'm unaware of?

Thanks for your help.

20th July 2011, 09:59 AM
Try this

create 2 text files in your home directory

touch myfile && touch test

In the test file put this in it. Adjust for your directory names etc.
#!/bin/bash -x

# Script to test a rpm scriplet

if [ -e /home/username/myfile ]; then
mv /home/username/myfile /home/username/myfile.bak
touch /home/username/myfile.itworked
Then to make it executable
chmod +x test

then run the script from your terminal with


and see if it works, if so and it should, then add to the %pre section in your .spec file.

You should see the renamed file myfile.bak and myfile.itworked

If the file "myfile" is empty, nothing happens with the -s file test, only if it is not empty. If the file exists, empty or not, then the -e file test might be preferable.

If you search for common file tests you will find more assistance, this is just one.

20th July 2011, 04:59 PM
Thank you for your reply - it helped me figure out what my issue was. If you look at my code and then look at yours, I had the semicolons in the incorrect place, and none of my code ran. I changed it, and it performed exactly as it should.

Thanks again!

Ust-Labinsk - Hortaleza Travel Photos - Offa Photos on Instagram