Sponsored Content
Full Discussion: Simple bash script help
Top Forums Shell Programming and Scripting Simple bash script help Post 302483424 by dentex on Monday 27th of December 2010 05:01:58 AM
Old 12-27-2010
Thanks

Thank you for the reply!
I'm not really sure of what you mean with "catalog", but the main thing is that I have to figure out what "uniq" and "xargs" commands do.

In the meantime, in my way, I accomplished the task; maybe it's not so elegant, but at least it works! :P

Code:
#!/bin/bash

tot1=`ls /var/cache/apt/archives | grep -c deb`

echo apt-get autoclean...
sleep 1
sudo apt-get autoclean

echo installed packages back-up...
sleep 1
cd /var/cache/apt/archives
sudo mkdir cache-backup

for c in `ls | sed 's/_.*//'`; 
    do for s in `dpkg --get-selections`;
        do case $c in
            $s) echo backing-up $c && sudo cp -r $c*deb --target-directory=cache-backup;
        esac 
    done
done

sleep 1
tot2=`ls /var/cache/apt/archives | grep -c deb`
bup=`ls /var/cache/apt/archives/cache-backup | grep -c deb`
echo ---------------------------
echo "total packages in cache were: $tot1"
echo "packages after auto-cleaning: $tot2"
echo "installed packages to retain in cache: $bup"
echo ---------------------------
sleep 2
echo removing entire cache...
sudo rm *.deb
sleep 2

echo restoring backed-up packages...
sudo cp /var/cache/apt/archives/cache-backup/*.deb /var/cache/apt/archives
sudo rm -r /var/cache/apt/archives/cache-backup
sleep 2

echo closing...
sleep 2
exit

...all stuffed with a lot of useless echoes, since I know exactly what the script does: removing from the cache in "/var/cache/apt/archives" all not installed packages.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple Bash Script

I'm sure I'm doing something wrong but as I am new to bash shell scripting I'm not sure what: Here's the code webalizer.conf is sitting in the same directory as this file which is named webalizer.sh. Can someone tell me if I've got the syntax right -- it that's correct? I'm executing the... (3 Replies)
Discussion started by: xaphalanx
3 Replies

2. Shell Programming and Scripting

Simple BASH script?

Hi guys, I'm new to the forum so forgive me if I'm sounding ... daft. I currently work in a Tech Support role. Every day we have to generate data by running around 10 .sh scripts. I was thinking instead of having to ./filename 10 times is it possible to right a new script that will run these for... (16 Replies)
Discussion started by: JayC89
16 Replies

3. Shell Programming and Scripting

simple bash script

I am writing a shell script in bash one of the thing I want to show is size of export /home du -sk /export/home/oracle | cut -c 1-5 echo "kbytes" when I run the script kbytes shows up in the second line, How can I append kbytes on the same line, such as 61233 kbytes please guide thanks (2 Replies)
Discussion started by: Tirmazi
2 Replies

4. Shell Programming and Scripting

Simple BASH script not working?

So I need a script that does the following: If a certain user is logged in Run `command` Else Echo “incorrect user” This is my first stab...which doesn't work: #!/bin/bash X="user=`ls -l /dev/console | cut -d " " -f 4`" Y="foobar" echo $X echo $Y (4 Replies)
Discussion started by: doubleminus
4 Replies

5. Shell Programming and Scripting

simple bash script permission

I have a bash script, but it needs to have a simple protection with password. So if a user wants to run the script , there should be a kdialog to asks for a password.If the password is correct the script starts to run. It should not be the passord of root or another admin user.Just a password in... (2 Replies)
Discussion started by: poort
2 Replies

6. Shell Programming and Scripting

Help with writing simple bash script

I want to write a bash script to: 1. Send an email from localhost to an external gmail account. (gmail then automatically forwards the message back to a pop account on the same server. 2. Script waits 3 minutes then checks to see if the email arrived, and if not, it sends an email to... (9 Replies)
Discussion started by: sallyanne
9 Replies

7. Shell Programming and Scripting

need a simple bash script

to gather the cpu utilization from a system in 5 minute intervals and direct output to file. I'm new at scripting and while this seems like an easy task I'm confused on where to start. thanks for any help (1 Reply)
Discussion started by: mkeyes001
1 Replies

8. Shell Programming and Scripting

Stumped on simple BASH Script

Hello All, First and foremost, if I have posted this question in the wrong forum/section, I apologize. Okay so here is my dilemma. I have written a BASH script that automatically restarts a tomcat on a given server. That part was simple enough. However, now I would like to not only restart... (14 Replies)
Discussion started by: UNM_Lobo
14 Replies

9. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

10. Shell Programming and Scripting

Simple Bash Script - Crontab

I've put together a very simple bash script to check for software patches and bounce the server, once complete. This is on a Mac server. The script works just fine upon execution, however, cron responds with: /bin/sh: /usr/local/bin/softwareupdates.sh: No such file or directory Crontab: ... (6 Replies)
Discussion started by: Nvizn
6 Replies
AXI-CACHE(1)							   User Commands						      AXI-CACHE(1)

NAME
axi-cache - query the Apt Xapian Index SYNOPSIS
axi-cache [options] command [args] DESCRIPTION
Query the Apt Xapian index. Commands: search commands: axi-cache again [query] repeat the last search, possibly adding query terms axi-cache help show a summary of commands axi-cache info print information about the apt-xapian-index environment axi-cache last [count] show the last results again axi-cache more [count] show more terms from the last search axi-cache rdetails pkgname[s] show details of reverse relationships for the given packages axi-cache search [terms] start a new search apt-cache front-ends: axi-cache depends pkgname[s] run apt-cache depends pkgname[s] axi-cache madison pkgname[s] run apt-cache madison pkgname[s] axi-cache policy pkgname[s] run apt-cache policy pkgname[s] axi-cache rdepends pkgname[s] run apt-cache rdepends pkgname[s] axi-cache show pkgname[s] run apt-cache show pkgname[s] axi-cache showpkg pkgname[s] run apt-cache showpkg pkgname[s] axi-cache showsrc pkgname[s] run apt-cache showsrc pkgname[s] OPTIONS
--version show program's version number and exit -h, --help show this help message and exit -s SORT, --sort=SORT sort by the given value, as listed in /var/lib/apt-xapian-index/values. Add a '-' to reverse sort order --tags show matching tags, rather than packages --tabcomplete=TYPE suggest words for tab completion of the current command line (type is 'plain' or 'partial') --last use 'show --last' to limit tab completion to only the packages from the last search results --all disable pagination and always show all results. Note that search results are normally sorted by relevance, so you may find meaning- less results at the end of the output axi-cache 0.45 December 2011 AXI-CACHE(1)
All times are GMT -4. The time now is 03:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy